noisy
noisy

Reputation: 6783

How to quickly mark resolution having conflicts during rebase?

this is a part of my git status

# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       deleted by us:      ../../src/generic/asdfgsdfgsfg.java
#       deleted by us:      ../../src/generic/bsdfgsdf.java                                                                                                                                                             
#       deleted by us:      ../../src/generic/cdghdfgh.java                                                                                                                                                              
#       deleted by us:      ../../src/generic/dghkghjk.java                                                                                                                                                           
#       deleted by us:      ../../src/generic/eghkghjk.java                                                                                                                                                       
#       deleted by us:      ../../src/generic/fsdfgsdfg.java                                                                                                                                                    
#       deleted by us:      ../../src/generic/gsdfgsd.java                                                                                                                                                        
#       deleted by us:      ../../src/generic/hdsfgsdfg.java                                                                                                                                                    
#       deleted by us:      ../../src/generic/isdgsdfg.java                                                                                                                                                     
#       deleted by us:      ../../src/generic/jdsfgsd.java                                                                                                                                                    
#       deleted by us:      ../../src/generic/ksdf.java                                                                                                                                                       
#       deleted by us:      ../../src/generic/lnsfgnsg.java                                                                                                                                                             
#                   

How can I easily and quickly make git rm on each of this file, knowing that in folder ../../src/generic/ there are a lot of other files, which I don't want to remove.

Upvotes: 5

Views: 1500

Answers (1)

Cascabel
Cascabel

Reputation: 496772

There's this really great pair of aliases I picked up from the git wiki a while back (it's currently down along with kernel.org):

edit-unmerged = \
    "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; vim `
add-unmerged = \
    "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"

This could be reimplemented in terms of git status --porcelain, which didn't exist when the tip was written, which would make it easier to rewrite edit-unmerged to avoid including deletion conflicts, since usually you want to delete/keep those, not edit them. But add-unmerged fits your use case exactly!

Something like this (untested):

add-unmerged = \
    "!f() { git status --porcelain | grep '^[ADU][ADU]' | cut -d" " -f2 }; git add `f`"
edit-unmerged = \
    "!f() { git status --porcelain | grep '^UU' | cut -d" " -f2 }; git add `f`"

with tweaking on the second pattern until it includes only the types of conflicts you like to edit. You definitely want UU; you might also want AU/UA, and maybe even AA. A for added, D for deleted, U for unmerged (modified).

Upvotes: 4

Related Questions