1

I'm having an issue upon merging to master in git. A file that I was working on in my local branch (old.file) has been moved and renamed in master (to new.file). After merging master into my branch I now have the new file and working changes on the old file.

How do I move changed contents of old.file into new.file? I only want to move the 20-something changed lines of old.file into new.file and then delete old.file.

1 Answer 1

2

Store diff/patch

You're going to need a patch/diff of what your looking to do. You can do this in multiple ways but I find the easiest way is the following:

git diff <some SHAid or HEAD^ or etc...> -- old.file > changes.diff

Modify diff

Now we're going to want to change the diff so that it can be applied to the new.file

change the

---a/old.file +++b/old.file 

to

---a/new.file +++b/new.file 

Apply the diff

now that the patch is going to be pointing to the correct file

git apply changes.diff

Cleanup (optional)

Be sure to remove the old.file from the repo (and local file) as it is probably no longer needed.

git rm old.file

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.