4

I have created a new branch from an existing branch:

git checkout master
git checkout -b test

then in the new branch I've renamed a file:

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

meanwhile someone else has edited the fooNew.txt on the master branch and pushed the changes:

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

now when I try and pull in the changes from master I get an error:

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

how can I merge these 2 branches so that I end up with a foo.txt file containing the changes done to fooNew.txt on master?

tempestSA
  • 149
  • 2
  • 8
  • 1
    Did you merge `test` to your `master` before the `git pull` command? If not, merge `master` to `test`, resolve conflict, then merge back to `master`. If already merged then you need to revert your master to previous commit beforehand. – JScoobyCed Nov 09 '12 at 01:19
  • 2
    Did you try to rebase? `git pull --rebase origin master` – iltempo Nov 09 '12 at 01:20
  • Thanks, I've tried `git pull --rebase origin master` and merging test to master first but I still get the same issue, a conflict that can either be resolved by saving the modified foo.txt file or deleting it. I've also tried rebasing master with test but no luck... – tempestSA Nov 09 '12 at 03:32
  • I gave up and did a merge, saved the modified file and then did a manual merge to pull in all changes between fooNew.txt and foo.txt (and then deleting fooNew.txt once I was done). But I am quite interested if there is a solution that doesn't involve manual merging. – tempestSA Nov 09 '12 at 04:40
  • Interesting read: http://stackoverflow.com/questions/11331494/git-merge-strategy-to-ignore-deleted-files – VonC Nov 09 '12 at 08:02

1 Answers1

0

Using your method, I had no problem.

$ 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(-)
Zombo
  • 1
  • 62
  • 391
  • 407