合并错误的提交

时间:2019-06-27 15:10:26

标签: git git-commit merge-conflict-resolution

我有我不太了解的git行为:

我有生产分支B1。

git checkout B1
git checkout -b B2

我正在研究一个解决方案,将其与B1语言环境合并

git checkout B2
git rebase B1
git checkout B1
git merge B2
git branch -d B2

然后,我执行相同的例程-从B1创建分支B3,在B3上工作,然后与B1合并。现在发生了多个合并冲突(实际上是在每次B2提交之间)。因此,我像对B2一样重新定标并合并它们。 代码被感激地拉动,git status显示B1或B3上没有任何提交。

后来,当我的同事撤出B1时,他再次面对了所有合并冲突。一场噩梦,我虽然不应该发生。

有人知道如果没有解决提交的提交,合并冲突怎么可能移到远程了?我想回想一下我没有重复过的(可能很严重的)错误^^

___ edit 故事表单控制台:

git checkout -b B2
git add file1
git commit -m "b2c1"
git rebase B1
git add file1
git commit -m "b2c2"
git push
git rebase B1
git checkout B1
git pull
git checkout B2
git rebase B1
git add file1
git commit -m "b2c3"
git rebase B1
git merge B1
git push B1
git checkout B1
git pull
git merge B2
git push
git branch --merged master
git branch -d B2
git checkout -b B3
git pull
git add file1
git commit -m "b3c1"
git push
git rebase -i HEAD~5
git push -f
git add file1
git commit -m "b3c2"
git add file2 file3 file4
git commit -m "b3c3"
git stash
git pull
git push 
git checkout B3
git stash push
git stash save
git stash apply
git checkout B3
git rebase B1
git checkout -- .
git checkout B1
git merge B3
git push

沿着这些路线,我不得不压缩更多的线路,否则将会是200/400的线路日志。

1 个答案:

答案 0 :(得分:0)

git add file1
git commit -m "b2c1"
git rebase B1

由于 b2c1 的直接父级是B1,因此不需要 rebase 。假设B2是在初始步骤中从B1创建的。

git commit -m "b2c2"
git push
git rebase B1

为什么要在 push 之后执行 rebase ,这很不直观。我建议不要先进行推送,然后再按照推送

的方式设置本地历史记录,然后再发布
git checkout B1
git pull

好的,这将根据远程当前拥有的内容更新您的本地 B1

git checkout B2
git rebase B1

这是我认为实际上有必要的第一个变基,但前提是 B1 已更改。

git add file1
git commit -m "b2c3"
git rebase B1

同样,您有不需要的 rebase

git merge B1

此时您无需将 B1 B 合并到 B2 ,因为 B1 没变。

似乎您可能对git及其运作方式有一些基本的误解。如果您是git的新手,那并不奇怪。我花了一些时间把头缠住它。 我建议您看看 Pro Git 书:https://git-scm.com/book/en/v2 帮助理解一些基本概念。

我最好的建议是尝试使事情保持简单,原子化和故意化。牢记这些事项将极大地帮助您。

git push B1
git checkout B1
git pull
git merge B2
git push
git branch --merged master
git branch -d B2
git checkout -b B3
git pull
git add file1
git commit -m "b3c1"
git push
git rebase -i HEAD~5
git push -f
git add file1
git commit -m "b3c2"
git add file2 file3 file4
git commit -m "b3c3"
git stash
git pull
git push 
git checkout B3
git stash push
git stash save
git stash apply
git checkout B3
git rebase B1
git checkout -- .
git checkout B1
git merge B3
git push
相关问题