使用 git 和 Vim 或 textmate 等编辑器时,一次性编辑冲突文件的最简单方法是什么?
我正在尝试进行一些调整
当我在命令行上输入 git status 时,我会得到一个需要解析的文件列表,如下所示:
# 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
是否有一种简单的方法可以将此文件路径列表传递到文本编辑器中,所以你可以一次性编辑它们吗?
例如,我可以通过简单地通过 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
但我不确定如何仅使用 shell 命令返回它,或者是否最简单地放入 ruby 或 python 中,通过正则表达式传递每一行,以过滤掉#两者都修改了:
。
我想要的最终结果是这样的:
vim #{space_separated_list_of_files}
你们会怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我的 gitconfig 中的一对别名,取自 git wiki :
应该做你想做的事!
Here are a pair of aliases I have in my gitconfig, taken from the git wiki:
Should do what you want!
我能想到的最短:
Shortest I can think of:
您知道 git mergetool 命令吗?这不会一次性打开所有文件,而是迭代所有需要的文件,这可能只是您需要的文件。您甚至可以使用 vim 进行合并
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