2016-09-26 118 views
0

我有一个分支B,它在另一个repo中签出,然后在那里进行了一些更改,在重新绑定之后,他们被--force(这是对最后一个承诺)。 现在,如果我将更改的分支拉入第一个回购库,我会合并冲突。将rebase结果拉入合并冲突

我运行的命令(与不相关的变化,即简化的实际输出)如下:

# 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://[email protected]/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 
... 

分支的两个副本之间的唯一区别是在“顶部”提交。 是否有可能告诉git,我想用第一个回购中的最后一个提交替换上游没有的git-pull试图查看相应文件中的更改?

+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搜索),

+0

好吧,所有的内容,重要的是从第二个副本推到上游。所以,我唯一需要的是在第一个分支中获取与第二个分支和上游分支相同的数据。 – Student4K

+0

也许我误解了你的问题。看到我的其他评论。 –