git 常用的函数
冲突解决
git reset SOFT –> 当commit 后,发现别人已经做了修改, 则先revert commit, 再pull 代码, 再merge, 再commit, push
提取patch
git format-patch -1 xxxxxxx-patch-uuid —> 提取某个patch
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 format-patch -M master //当前分支所有超前master的提交
git format-patch -s SHA值 //此SHA值提交以后的所有PATCH
git format-patch -1 SHA值 //此SHA值的提交patch
git format-patch -n //从master售前n个提交的内容
git format-patch -n SHA值 //从SHA值开始(含SHA值当次)之前的N次提交
git format-patch HEAD^ <==最近的1次commit的patch
git format-patch HEAD^^ <==最近的2次commit的patch
git format-patch HEAD^ <==最近的3次commit的patch
git format-patch HEAD^ <==最近的4次commit的patch
git format-patch HEAD^^^^^ <==不支持!!!!error!!!
链接:https://www.jianshu.com/p/f4c2a5d75fed
|
rebase 到master
1 2 3 4
| 1. 提交代码到自己分支 2. 切换到master, 拉取最新的代码 3. 切换到自己分支 4. git rebase master
|
合并提交
https://www.cnblogs.com/amou/p/9465880.html
git rebase -i checkin-uuid (最常用的是类似 git rebase -i HEAD~2)
git push -f origin branch-name-xxxx
同步fork的分支
- 先添加 remote 源
1
| git remote add remote_origin git@github.com:***/***.git
|
- 获取原始仓库分支和对应的提交
- 更新git remote 中所有的远程repo 所包含分支的最新commit-id, 将其记录到.git/FETCH_HEAD文件中
- 把原始remote_origin/master的改变合并到你本地的master分支。这会使你fork的分支master 与上层仓库remote_origin repository同步,而不会丢失你本地所做的改变:
1 2 3
| git merge remote_origin/master // or git rebase remote_origin/master
|
- 提交本地代码到github
- 删除远程upstream
1
| git remote rm remote_origin
|
删除提交记录
i代表要恢复到多少次提交前的状态,如指定i = 2,则恢复到最近两次提交前的版本。–soft代表只删除服务器记录,不删除本地。
再执行
1
| git push origin master --force
|
master代表当前分支
分支管理
- 查看本地及远程所有分支
1 2
| git fetch origin git branch -a
|
- 删除本地分支
- 删除远程分支
1
| git push origin --delete dev
|
- 切换远程分支
1
| git checkout xxx -b my_edit_branch
|
github 仓库迁移
- clone 老的项目 为裸
1
| git clone --bare git://www.aa.com/project_name.git
|
在github 创建一个空项目, 建议任何文件都不创建
将所有git 记录推送到新项目中
1 2
| cd project_name git push --mirror git@www.bbb.com/new_project_name.git
|
- 删除老文件, 并clone 新项目
1 2
| rm project_name git clone git@www.bbb.com/new_project_name.git
|