在 Git 工作区中检测修改文件的简单方法是什么? [英] What's an easy way to detect modified files in a Git workspace?

查看:33
本文介绍了在 Git 工作区中检测修改文件的简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 make 期间,我创建了嵌入在链接输出中的字符串字段.很有用.

During make, I create string fields which I embedded in the linked output. Very useful.

除了对 git status 命令进行复杂的 sed/grep 解析之外,我如何轻松确定工作区中的文件是否已被根据git修改?

Other than a complex sed/grep parsing of the git status command, how can I easily determine if files in the workspace have been modified according to git?

推荐答案

如果你只是想要一个简单的与 HEAD 有什么区别吗?":

If you just want a plain "Are there any differences from HEAD?":

git diff-index --quiet HEAD

如果退出代码为 0,则没有区别.

If the exit code is 0, then there were no differences.

如果您想要HEAD 更改了哪些文件?":

If you want "What files have changed from HEAD?":

git diff-index --name-only HEAD

如果您想从 HEAD 更改了哪些文件,它们以哪些方式更改(添加、删除、更改)?":

If you want "What files have changed from HEAD, and in what ways have they changed (added, deleted, changed)?":

git diff-index --name-status HEAD

如果要重命名(和复制)检测,请添加 -M(和 -C).

Add -M (and -C) if you want rename (and copy) detection.

这些命令将检查暂存内容(索引中的内容)和工作树中的文件.像 git ls-files -m 这样的替代方案只会根据索引检查工作树(即它们将忽略也在工作树中的任何暂存(但未提交)的内容).

These commands will check both the staged contents (what is in the index) and the files in the working tree. Alternatives like git ls-files -m will only check the working tree against the index (i.e. they will disregard any staged (but uncommitted) content that is also in the working tree).

这篇关于在 Git 工作区中检测修改文件的简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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