我注意到,在处理一两张票时,如果我走开,我不确定我在做什么,什么改变了,等等。
是否有一种方法可以在git添加和提交之前查看给定文件所做的更改?
我注意到,在处理一两张票时,如果我走开,我不确定我在做什么,什么改变了,等等。
是否有一种方法可以在git添加和提交之前查看给定文件所做的更改?
当前回答
git diff <path>/filename
路径可以是完整的系统路径,直到文件或 如果您在项目中,也可以粘贴修改后的文件路径 对于路径使用的修改文件:git状态
其他回答
git diff
显示工作树和索引或树之间的更改,索引和树之间的更改,两个树之间的更改,或磁盘上两个文件之间的更改。
git diff <path>/filename
路径可以是完整的系统路径,直到文件或 如果您在项目中,也可以粘贴修改后的文件路径 对于路径使用的修改文件:git状态
你要找的是
Git diff——阶段性的
根据你的具体情况,有三种有用的方法来使用git diff:
显示索引和工作树之间的差异;也就是说,你还没有提交的更改:
git diff [filename]
显示当前提交和索引之间的差异;也就是说,你要提交的东西(——staging做完全相同的事情,使用你喜欢的东西):
git diff --cached [filename]
显示当前提交和工作树之间的差异:
git diff HEAD [filename]
Git diff在目录上递归地工作,如果没有给出路径,它会显示所有更改。
转到你各自的git repo,然后运行以下命令:
Git diff文件名
它将打开文件与更改标记,按返回/回车键向下滚动文件。
P.S. filename应包括文件的完整路径,否则,您可以通过进入文件的相应目录/文件夹而不使用完整文件路径运行
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.