简体   繁体   中英

git merge “deleted by us”

I am doing a big merge. A lot of files have been removed from the repo in my branch, and in doing the merge I want to keep this change for all of those files. There are also some files that will need explicit merging and I'm intending to use git mergetool to merge them.

I wish to keep the "deleted by us" change (ie. the files should remain deleted) for all deleted files. Other merge conflicts I want to resolve myself.
Is there a way I can tell git to keep the deleted files deleted?

Here is a partial solution:

  1. Resolve all non deleted merge conflicts by hand, which you have to do anyway

  2. Type git diff --name-only --diff-filter=U to get a list of all remaining files in conflict. These files must be the ones you want deleted. Save the list of removed files as filesToRemove.txt

  3. Then do cat filesToRemove.txt | xargs git rm cat filesToRemove.txt | xargs git rm to remove all the files.

一行修复:

git diff --name-only --diff-filter=U | xargs git rm

You can resolve this by keeping the edited files by adding them back, and committing them once more:

git add .

or

git add -A

Then commit

git commit

If you want to resolve the confict by removing the files, you have to run git rm instead of git add .

See: Resolving a merge conflict from the command line

I'll leave the question - because I'm sure there is a good answer - this is what I have done in the mean time:

  1. Do git status to see the list of deleted files (1082) and the number that had merge conflicts (3)
  2. In a text editor manually edit the 3 files that had merge conflicts, and then do git add on them
  3. Create a text file with a line with the letter "d" on each line and nothing else for each of the (1082) files that had been deleted (d.txt)
  4. run git mergetool < d.txt

Not elegant, but faster than pressing the letter "d" and enter 1082 times

I also observed

abc.txt: needs merge

when attempting

git rm abc.txt

after cherry-picking and seeing the file in "deleted by us" status.

I ended up with a resolved delete by doing the following:

git add abc.txt
rm abc.txt
git add abc.txt

this adds abc.txt to the staging area (essentially recreating the "deleted by us" file. (which resolves the conflict status)

then deletes the files from the file system

then adds to the stating area the fact that the file is now gone.

there are probably shell tricks to run these 3 commands on your set of 1000+ files without much headache.

there are probably better ways to handle this, but since git rm abc.txt did not work as we expected for our situation(s) i thought i would share an alternative set of commands that seem to have worked without using the mergetool .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM