Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the simplest way to edit conflicted files in one go when using git and an editor like Vim or textmate?

I'm trying to tweak a little

When I type in git status on the commandline, I get a list of files that need to be resolved like so:

# Unmerged paths: #
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#   both modified:      apache2/templates/default/apache2.conf.erb
#   both modified:      bootstrap/attributes/default.rb
#   both modified:      iptables/metadata.rb
#   both modified:      kickstart/templates/default/ks.cfg.erb
#   both modified:      openssl/metadata.json
#   both modified:      postfix/metadata.json
#   both modified:      postfix/templates/default/main.cf.erb

Is there a simple way to pass this list of file paths into a text editor, so you can edit them all in one go?

I can get to this for example, by simply piping it through grep:

[17:37]:git status | grep "both modified"
#   both modified:      apache2/templates/default/apache2.conf.erb
#   both modified:      bootstrap/attributes/default.rb
#   both modified:      iptables/metadata.rb
#   both modified:      kickstart/templates/default/ks.cfg.erb
#   both modified:      openssl/metadata.json
#   both modified:      postfix/metadata.json
#   both modified:      postfix/templates/default/main.cf.erb

But I'm not sure how to return this using just shell commands, or whether it's simplest to drop into ruby or python, to pass each line through a regexp, to filter out the # both modified:.

The end result I want is something like this:

vim #{space_separated_list_of_files}

How would you guys do this?

like image 748
Chris Adams Avatar asked Jul 04 '10 07:07

Chris Adams


3 Answers

Shortest I can think of:

vim `git status|grep 'both modified'|cut -d: -f2`
like image 161
Thomas Avatar answered Nov 15 '22 19:11

Thomas


Here are a pair of aliases I have in my gitconfig, taken from the git wiki:

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

Should do what you want!

like image 39
Cascabel Avatar answered Nov 15 '22 19:11

Cascabel


Are you aware of the git mergetool command ? That doesn't open all the files in one go, but iterate on all needed files, which might be only what you need. You can even use vim to do the merge

git mergetool --tool=vimdiff

like image 28
mb14 Avatar answered Nov 15 '22 20:11

mb14