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

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


当前回答

Git diff文件名

其他回答

如果您不确定您所做的更改的文件,并希望在提交到本地分支之前了解更改,请使用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快乐……

git diff

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

你也可以使用git友好的文本编辑器。它们显示已修改的行上的颜色,添加的行显示另一种颜色,删除的行显示另一种颜色,等等。

GitHub的Atom 1.0就是一个很好的文本编辑器。

Git diff文件名

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.