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?
Shortest I can think of:
vim `git status|grep 'both modified'|cut -d: -f2`
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With