将rebase结果拉入合并冲突后

时间:2016-09-26 14:29:53

标签: git rebase pull

我有一个分支B,在另一个仓库中检出,然后在那里进行了一些更改,在rebase之后,他们被推送到--force(这是最后一次提交的修正)。 现在,如果我将更改后的分支拉入第一个仓库,我就会遇到合并冲突。

我运行的命令(无关的更改,简化实际输出)如下:

#   First checkout the original B
$ pwd
/home/user/dir1

$ git checkout B
Switched to branch 'B'
Your branch is up-to-date with 'origin/B'.

#   Now clone the same repo into another directory and checkout B there
$ cd .. && git clone git clone ssh://git@myhost/myrepo.git dir2 && cd dir2

$ git checkout B
Switched to branch 'B'
Your branch is up-to-date with 'origin/B'.

#   Now edit some file, commit it and "merge" the changes
#   to the originally last commit as a fixup
$ nano file.txt
$ git commit -a -m "Fixup to file.txt"
$ git rebase -i HEAD~2
... the last commit is "fixup'ed" to the last commit in the original branch (the commit before "Fixup to the file.txt" commit

#   Push the B with rewritten history to the upstream
$ git push --force origin B

#   Get back to the original repo and pull the changes
$ cd ../dir1
$ git pull origin B
...
CONFLICT (content): Merge conflict in .../file.txt
...

分支的两个副本之间的唯一区别在于" top"承诺。 是否有可能告诉git,我想用第一个repo中的最后一次提交替换我在上游的内容而没有git-pull试图查看相应文件中的更改?

1 个答案:

答案 0 :(得分:0)

有像

这样的历史
...-A-B-C-D-E     # HEAD

其中Edir/中未更改的提交。我们将E'作为一个来自E的提交,但是从dir2进行了重新定位和强制推送。

dir中,您可以将HEAD倒回到之前的提交中:

git reset --hard HEAD^

获取

...-A-B-C-D        # HEAD
           \
            `-E    # dangling and invisible, will be garbage collected

之后

git pull upstream B

会给你什么

...-A-B-C-D-E'     # HEAD
           \
            `-E    # dangling and invisible, will be garbage collected

但请注意,您将丢失E的内容(除非您在reflog中搜索

相关问题