git - 您如何设置分支出现分歧的情况?
问题描述
我正在尝试重现分支出现分歧的情况(这样我就可以练习解决问题),正如这个问题中提到的那样:master 分支和“origin/master”已经分歧,如何“取消分歧”分支?
关于如何创建它的任何示例?
解决方案
一个。创建两个本地分支:
git init
git checkout -b master
echo aaa > a.txt && git add a.txt && git commit -m "first commit"
git checkout -b diverge
echo bbb > b.txt && git add b.txt && git commit -m "diverge: bbb"
echo ccc > c.txt && git add c.txt && git commit -m "diverge: ccc"
# return to 'master' branch (which is 2 commits behind 'left') :
git checkout master
echo ddd > d.txt && git add d.txt && git commit -m "master: ddd"
echo eee > e.txt && git add e.txt && git commit -m "master: eee"
# now 'master' and 'diverge' are two local branches, which diverge :
git log --oneline --graph diverge master
湾。如果您想要一个发散的遥控器,请将“发散”分支作为“主”分支推送到原点:
git push origin diverge:refs/heads/master
# you now have a 'origin/master' branch
# at the same time, set your local 'master' branch to track 'origin/master' :
git branch -u master origin/master
# now 'git status' on master should say 'ahead 2, behind 2'
git checkout master
git status
创建不同历史的其他方法:
创建一个 master 分支,将其推送到 orgin,然后运行
git rebase -i HEAD~3
例如,并编辑或删除第一个提交创建一个主分支,推送到原点,然后
git reset
将您的主分支推送到过去的某个提交,然后创建新的提交master
推荐阅读
- javascript - 如何在一个函数中使用多个 ID
- javascript - 计算排序数组中出现的次数(或频率)
- jquery - 滚动时获取到达区域的ID
- java - java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the value of DISPLAY variable
- javascript - css-loader / style-loader 的错误
- javascript - JS将数组转换为具有属性键/值的对象
- excel - Excel VBA:在 PowerPoint 中编辑瀑布工作簿
- oracle - 如何从 UTL_RAW.CAST_TO_VARCHAR2 函数输出固定长度值?
- elasticsearch - 如何将日志从多个服务器发送到 ELK 服务器
- c - () 语句之外的指针