我有两个分支:master
,br2
我很少提交并推送到origin/br2
现在我想将master
重新定义为br2
然后将其合并到master
并将我的所有新更改提交为一个大提交。
这是我做的:
git fetch --all
git checkout br2
git rebase origin/master
git rebase --continue until I resolved all conflicts
-checked everything is working
git checkout master
git merge br2
git commit review (my alias...can ignore)
git checkout br2
git rebase master (should have done nothing, no?)
q:我必须先拉并再次解决所有冲突。为什么会这样?
q:我应该如何在git commit review
之前将所有提交压缩为一次提交?
我看到了这个:
git rebase -i master
That command will show a list of each commit, as such:
pick fb554f5 This is commit 1
pick 2bd1903 This is commit 2
pick d987ebf This is commit 3
# Rebase 9cbc329..d987ebf onto 9cbc329
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
Edit the summary shown to you by the rebase command, leaving the commit you want to be the main commit as "pick" and changing all subsequent "pick" commands as "squash":
pick fb554f5 This is commit 1
squash 2bd1903 This is commit 2
squash d987ebf This is commit 3
但我不确定,因为我已经检查了主人
答案 0 :(得分:0)
q1)如果您已经对b2
进行了一些更改,则需要使用强制推送。 git push origin/b2 --force
。这将使用重新定位的本地版本b2替换远程origin / b2。
q2)这应该可以用于压缩提交。
答案 1 :(得分:0)
关于git rebase。
它基本上做的是将所有提交从当前分支重写到基本分支。这意味着您的本地分支与远程分支不同(尽管提交应该几乎相同 - 除了冲突)。
您可以通过强制git push -f origin
推送您的本地分支到远程。