$ git init [project-name]#Creates a new local repository with the specified name
$ git clone [url]#Downloads a project and its entire version history
3. 做出改变
查看编辑并制作提交事务
$ git status
#Lists all new or modified files to be committed
$ gitadd[file]#Snapshots the file in preparation for versioning
$ git reset [file]#Unstages the file, but preserve its contents
$ gitdiff#Shows file differences not yet staged
$ gitdiff --staged
#Shows file differences between staging and the last file version
$ git commit -m "[descriptive message]"#Records file snapshots permanently in version history
4. 组变动
命名一系列提交并结合已完成的工作
$ git branch
#Lists all local branches in the current repository
$ git branch [branch-name]#Creates a new branch
$ git checkout [branch-name]#Switches to the specified branch and updates the working directory
$ git merge [branch]#Combines the specified branch’s history into the current branch
$ git branch -d [branch-name]#Deletes the specified branch
5. 重构文件名
重新定位和删除版本化文件
$ gitrm[file]#Deletes the file from the working directory and stages the deletion
$ gitrm --cached [file]#Removes the file from version control but preserves the file locally
$ gitmv[file-original][file-renamed]#Changes the file name and prepares it for commit
6. 同步更改
注册存储库书签并交换版本历史记录
$ git fetch [bookmark]#Downloads all history from the repository bookmark
$ git merge [bookmark]/[branch]#Combines bookmark’s branch into current local branch
$ git push [alias][branch]#Uploads all local branch commits to GitHub
$ git pull
#Downloads bookmark history and incorporates changes
7. 禁止跟踪
排除临时文件和路径
$ git ls-files --other --ignored --exclude-standard
#Lists all ignored files in this project
8. 保存片段
搁置和恢复不完整的更改
$ git stash
#Temporarily stores all modified tracked files
$ git stash list
#Lists all stashed changesets
$ git stash pop
#Restores the most recently stashed files
$ git stash drop
#Discards the most recently stashed changeset
9. 查看历史
浏览和检查项目文件的演变
$ git log
#Lists version history for the current branch
$ git log --follow [file]#Lists version history for a file, including renames
$ gitdiff[first-branch]...[second-branch]#Shows content differences between two branches
$ git show [commit]#Outputs metadata and content changes of the specified commit
10. 重做提交
擦除错误并制作更换历史
$ git reset [commit]#Undoes all commits after [commit], preserving changes locally
$ git reset --hard [commit]#Discards all history and changes back to the specified commit