In one branch in one branch A a file is cha开发者_Go百科nged and the change commited. Now in another branch B the very same file is edited and renamed.
When merging B into A git recognises the conflict properly (CONFLICT (delete/modify)) and both files are in the working directory.
If I know want to have both changes in one file, how do I do this best?
There is git merge-file that is - if I'm right - expecting both files and a common ancestor. But how to give latter? How can I say "use $path from $commit" or something like that?
Example:
mkdir git-rename-repo
cd git-rename-repo
git init
echo "First line" > afile
git add .
git commit -m "First commit in master"
git checkout -b mybranch
echo "Second line in mybranch" >> afile
git mv afile bfile
git commit -a -m "change and rename in mybranch"
git checkout master
echo "Changed first line in master" > afile
git commit -a -m "changed afile"
git merge mybranch
I now want a file named 'bfile' with both changes:
Changed first line in master
Second line in mybranch
Thanks
I also had the scenario
**CONFLICT (modify/delete):***FileName deleted in HEAD and modified in 6efb2a94ba0601aa1ec5050ab222a0359ee8379a. Version 6efb2a94ba0601aa1ec5050ab222a0359ee8379a of FileName left in tree.*
I was also equally confused and reached this post.
But on typing git status
, all doubts are vanished. git status
, stated the following about the conflicted files:
Unmerged paths:
(use "git add/rm ..." as appropriate to mark resolution)
So I just did git rm FileName
, and after that the CONFLICT got resolved.
On my case, it was a deleted file not present on the repository
CONFLICT (delete/modify): ERD.pdf deleted in HEAD and ...
I just need to do: git rm ERD.pdf
Hope that helps.
UPDATE Okay, git's recursive merge algorithm does this just fine by itself. I just used too small files to test it so the relative similiarity was beneath the trigger of the rename detection.
If I change one line of a file with two small lines the relative change is very big.
Of course I could do something like
git show HEAD^:afile > afile_ancestor
kdiff3 -m afile_ancestor afile bfile
P.S.: Sorry for the broken formatting above. I didn't had switched on JavaScript, so I couldn't see a preview.
git status
will help you here.
If you want to add files to current branch do git add <file-name>
If you want to remove/delete files from the current branch do git rm <file-name>
精彩评论