我的常用git命令
近期在频繁使用git很多命令不熟练,记录和学习一下
分支操作
- 创建与切换分支
1 2 3 4
| git branch git branch <branch-name> git checkout <branch-name> git checkout -b <branch-name>
|
- 分支合并
1 2 3
| git merge <branch-name> git merge --no-ff <branch-name> git rebase <branch-name>
|
- 删除分支
1 2 3
| git branch -d <branch-name> git branch -D <branch-name> git push origin --delete <branch-name>
|
- 查看分支关系
1 2 3
| git log --oneline --graph git branch -v git remote show origin
|
远程仓库同步
- 推送(Push)
1 2 3
| git push origin <branch-name> git push -u origin <branch-name> git push --force origin <branch-name>
|
- 拉取(Pull)
1 2 3
| git pull origin <branch-name> git fetch origin git fetch origin <branch-name>:<local-branch>
|
- 跟踪远程分支
1 2
| git checkout -t origin/<branch-name> git branch -u origin/<branch-name>
|
高频衍生操作
- 暂存与恢复工作区
1 2 3
| git stash git stash pop git stash list
|
- 撤销与重置
1 2 3
| git reset --hard HEAD^ git revert <commit-id> git checkout -- <file>
|
- 冲突解决
1 2 3
| git diff git mergetool git add <file>
|