创建远程仓库
init, remote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
mkdir git_repo cd git_repo git init
git remote add origin git@github.com:<github_user>/git_repo.git
git remote -v
git remote remove origin
|

add, commit, push
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
git status git add . git commit -m "..."
git add . git status git commit -m "..."
git add -A git commit -m "..."
git commit -a -m "..."
git push -u origin master
|
基于远程仓库修改
pull、clone
1 2 3 4 5 6 7 8 9 10 11 12
| cd git_repo git pull
git clone https://github.com/username/git_repo.git cd git_repo
git commit -a -m "..." git push
|
新建、切换分支
checkout
1 2 3 4 5 6 7
| cd git_repo
git checkout -b test git push -u origin test
git checkout test
|
修改历史提交
revert
1 2 3 4 5 6
| cd git_repo git pull git log
git revert HEAD
|
reset
1 2 3 4 5 6 7 8
| git reset --hard HEAD^
git reset --hard <commit_id>
git push origin master -f
|
rebase
1 2 3 4 5 6 7 8 9
| git rebase -i <commit_id>
git add . git commit --amend git rebase --continue
git push origin master -f
|
rebase前:

rebase到5c9af:
执行git rebase -i <commit_id>后,会自动打开一个文件,pick表示选取某些提交,edit表示选取并编辑某些提交:



因上面修改了2行为edit,edit第二次:

(End)