更简单的方式在Git中仅对已修改的文件进行分段(未删除) [英] Simpler way to stage only modified files in Git (not deleted)

查看:104
本文介绍了更简单的方式在Git中仅对已修改的文件进行分段(未删除)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作分支中有一堆已删除的文件,我不确定我想要提交。我需要根据需要提交修改过的文件。



这就是我想到的:

  git add` git status | grep修改|切-f2 | cut -f4 -d''`

这个答案有类似的效果,但并没有太大的改善:< a href =https://stackoverflow.com/a/8277826> https://stackoverflow.com/a/8277826



所以那里一个简单的解决方案?

解决方案

只需使用 git add --no-all。(Git v。2.0+)或 git add。(Git v。1.x)。这将通过遍历当前目录来获取它可以找到的任何文件,这当然不会包含已删除的文件。



当然,这也会拾取任何未跟踪的文件。如果你需要避免这些,那么你可以使用更复杂的表达式。它和你的类似,但它使用了用于脚本编写的输出(所以它更稳定,更易于解析):

  git diff-files -z --diff-filter = M --name-only --relative | xargs -0 git add 


I have a bunch of deleted files in my working branch that I'm not sure I want to commit yet. I need to commit my modified files as needed though.

This is what I came up with:

git add `git status | grep modified | cut -f2 | cut -f4 -d' '`

This answer does something similar but isn't much better: https://stackoverflow.com/a/8277826

So is there a simpler solution?

解决方案

Just use git add --no-all . (Git v. 2.0+) or git add . (Git v. 1.x). This will pick up any files it can find by traversing the current directory, which naturally won't include deleted files.

Of course, this also picks up any untracked files too. If you need to avoid those, then you can use a more complicated expression. It's similar to yours, but it uses the output that's intended for scripting (so it's more stable and easier to parse):

git diff-files -z --diff-filter=M --name-only --relative | xargs -0 git add

这篇关于更简单的方式在Git中仅对已修改的文件进行分段(未删除)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆