4

我从现有分支创建了一个新分支:

git checkout master
git checkout -b test

然后在新分支中我重命名了一个文件:

git mv foo.txt fooOld.txt
git mv fooNew.txt foo.txt
git commit -am "Rename file"

与此同时,其他人在主分支上编辑了 fooNew.txt 并推送了更改:

git co master
echo "Some changes" >> fooNew.txt
git commit -am "Do some important changes"
git push origin master

现在,当我尝试从 master 中提取更改时,出现错误:

CONFLICT (modify/delete): fooNew.txt deleted in HEAD and modified in master.

如何合并这两个分支,以便最终得到一个 foo.txt 文件,其中包含对 master 上的 fooNew.txt 所做的更改?

4

1 回答 1

0

使用你的方法,我没有问题。

$ git checkout -b test
Switched to a new branch 'test'

$ git mv foo.txt fooOld.txt

$ git mv fooNew.txt foo.txt

$ git commit -am "Rename file"
[test bf82f6d] Rename file
 1 files changed, 0 insertions(+), 0 deletions(-)
 rename fooNew.txt => fooOld.txt (100%)

$ git checkout master
Switched to branch 'master'

$ echo "Some changes" >> fooNew.txt

$ git commit -am "Do some important changes"
[master 653c0df] Do some important changes
 1 files changed, 1 insertions(+), 0 deletions(-)

$ git checkout test
Switched to branch 'test'

$ git merge master
Auto-merging fooOld.txt
Merge made by the 'recursive' strategy.
 fooOld.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
于 2012-12-14T05:44:22.190 回答