Git 操作详细总结,以便回顾和查询。理解这些指令,觉得最重要的是理解 Git 的内部原理,比如 Git 的分布式版本控制,分清楚工作区、暂存区、版本库,还有就是理解 Git 跟踪并管理的是修改,而非文件。

设置
1 2
| git config --global user.name "Your Name" git config --global user.email "email@example.com"
|
提交
Git 追踪的是修改,而不是文件。

1 2 3 4 5
| git add filename.txt
git commit -m "Add filename.txt."
|
状态
回退
1 2 3 4 5 6 7 8 9 10 11 12 13
| git checkout -- file.name git checkout -- .
git reset --soft HEAD
git reset HEAD git reset --mixed HEAD
git reset --hard HEAD
|
记录
删除
1 2 3
| rm file.name git rm file.name git commit -m "Del"
|
远程操作
1 2 3 4 5
| git remote add origin git@github.com:ifyour/ifyour.github.io.git
git push -u origin master git push origin master
|
克隆
1 2
| git clone https://github.com/ifyour/ifyour.github.io.git path git clone git@github.com:ifyour/ifyour.github.io.git path
|
分支操作

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| git branch
git branch dev
git checkout dev
git checkout -b dev
git merge dev
git branch -d dev
|
标签
1 2
| git tag 0.1.1 git push origin --tags
|
More