我注意到,在处理一两张票时,如果我走开,我不确定我在做什么,什么改变了,等等。

是否有一种方法可以在git添加和提交之前查看给定文件所做的更改?


当前回答

对于某些路径,其他答案将返回一个致命形式的错误:模糊的参数。

在这些情况下,diff需要一个分隔符来区分文件名参数和提交字符串。例如,要回答问题,你需要执行:

$ git diff --cached -- <path-to-file>

这将显示修改后的文件与上次提交之间的更改。

另一方面:

git diff --cached HEAD~3 <path-to-file>

将显示本地版本与三次提交前版本之间的更改。

其他回答

使用git-diff:

git diff -- yourfile

Git diff文件名

git diff <path>/filename

路径可以是完整的系统路径,直到文件或 如果您在项目中,也可以粘贴修改后的文件路径 对于路径使用的修改文件:git状态

For me git add -p is the most useful way (and intended I think by git developers?) to review all unstaged changes (it shows the diff for each file), choose a good set of changes that ought to go with a commit, then when you have staged all of those, then use git commit, and repeat for the next commit. Then you can make each commit be a useful or meaningful set of changes even if they took place in various files. I would also suggest creating a new branch for each ticket or similar activity, and switch between them using checkout (perhaps using git stash if you don't want to commit before switching), though if you are doing many quick changes this may be a pain. Don't forget to merge often.

git diff

显示工作树和索引或树之间的更改,索引和树之间的更改,两个树之间的更改,或磁盘上两个文件之间的更改。