使用 git 和 Vim 或 textmate 等编辑器时,一次性编辑冲突文件的最简单方法是什么?

发布于 2024-09-08 03:12:30 字数 1361 浏览 2 评论 0原文

我正在尝试进行一些调整

当我在命令行上输入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2024-09-15 03:12:30

这是我的 gitconfig 中的一对别名,取自 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`"

应该做你想做的事!

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!

会傲 2024-09-15 03:12:30

我能想到的最短:

vim `git status|grep 'both modified'|cut -d: -f2`

Shortest I can think of:

vim `git status|grep 'both modified'|cut -d: -f2`
淡淡的优雅 2024-09-15 03:12:30

您知道 git mergetool 命令吗?这不会一次性打开所有文件,而是迭代所有需要的文件,这可能只是您需要的文件。您甚至可以使用 vim 进行合并

git mergetool --tool=vimdiff

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文