我注意到,在处理一两张票时,如果我走开,我不确定我在做什么,什么改变了,等等。
是否有一种方法可以在git添加和提交之前查看给定文件所做的更改?
我注意到,在处理一两张票时,如果我走开,我不确定我在做什么,什么改变了,等等。
是否有一种方法可以在git添加和提交之前查看给定文件所做的更改?
当前回答
转到你各自的git repo,然后运行以下命令:
Git diff文件名
它将打开文件与更改标记,按返回/回车键向下滚动文件。
P.S. filename应包括文件的完整路径,否则,您可以通过进入文件的相应目录/文件夹而不使用完整文件路径运行
其他回答
使用git-diff:
git diff -- yourfile
Git diff文件名
对于某些路径,其他答案将返回一个致命形式的错误:模糊的参数。
在这些情况下,diff需要一个分隔符来区分文件名参数和提交字符串。例如,要回答问题,你需要执行:
$ git diff --cached -- <path-to-file>
这将显示修改后的文件与上次提交之间的更改。
另一方面:
git diff --cached HEAD~3 <path-to-file>
将显示本地版本与三次提交前版本之间的更改。
好吧,我的情况下,当你不想关心文件列表。让他们都看看。
当你已经运行git添加到你的文件列表:
$ git diff --cached $(git diff --cached --name-only)
在git的最新版本中,您可以使用—staging also,这是—cached的同义词。
同样可以用于没有添加文件但没有——cached选项。
$ git diff $(git diff --name-only)
“cached”选项的Git命令别名:
$ git config --global alias.diff-cached '!git diff --cached $(git diff --cached --name-only)'
如果您不确定您所做的更改的文件,并希望在提交到本地分支之前了解更改,请使用git add -p,它可以帮助您在接受添加到本地分支之前验证更改。 使用这个查询
舞台这个大块头[y,n,q,a,d,/,j, j, g,e,?]? 将为您提供多个选项,如y表示分期更改,n表示不分期更改等。
Other options: q - quit; do not stage this hunk nor any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk nor any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
希望能有所帮助!!git快乐……