How can I see what has changed in a file before committing to git?
我注意到,当我处理一两张票的时候,如果我离开,我不知道我在做什么,做了什么改变,等等。
在git add和git commit之前,是否有方法查看对给定文件所做的更改?
你在找
1 2 3 4 5 6 7 8 9 | # show differences between index and working tree # that is, changes you haven't staged to commit git diff [filename] # show differences between current commit and index # that is, what you're about to commit # --staged does exactly the same thing, use what you like git diff --cached [filename] # show differences between current commit and working tree git diff HEAD [filename] |
号
它将在目录上递归工作,如果没有给定路径,它将显示所有更改。
使用
1 | git diff yourfile |
对我来说,
江户十一〔一〕号
埃多克斯1〔2〕
Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, or changes between two files on disk.
号
记住,您提交的是更改,而不是文件。
因为这个原因,我很少不使用
嗯,我的情况是,当你不想关心文件列表。把他们都展示出来。
当您已经使用文件列表运行
1 | $ git diff --cached $(git diff --cached --name-only) |
。
这同样适用于没有添加文件但没有
1 | $ git diff $(git diff --name-only) |
"cached"选项的git命令别名:
1 | $ git config --global alias.diff-cached '!git diff --cached $(git diff --cached --name-only)' |
。
1 | git diff <path>/filename |
路径可以是完整的系统路径,直到文件或如果您在项目中,也可以粘贴修改后的文件路径对于使用路径的修改文件:
转到各自的git repo,然后运行以下命令:
Git diff文件名
它将打开标记有更改的文件,按回车/回车键向下滚动该文件。
p.s.文件名应包含文件的完整路径,否则,您可以在文件的相应目录/文件夹中运行而不使用完整文件路径。
您还可以使用Git友好的文本编辑器。它们显示已修改的线条上的颜色、添加线条的另一种颜色、删除线条的另一种颜色等。
一个好的文本编辑器就是Github的Atom 1.0。