问题描述
这经常发生在我身上:我在一两天的时间里同时处理一对夫妇相关的变化,当时间到了提交时,我最终忘记了特定文件中更改的内容。 (这只是个人的git回购,所以我可以在提交中有多个更新。)
有什么方法可以预览我本地文件,即将被检入,以及该文件的最后一次提交?
类似于:
git diff --changed / myfile。 txt
它会打印出如下内容:
第23行
(上次提交):var = 2 + 2
(current):var = myfunction()+ 2
行149
(上次提交):返回var
(当前):return var / 7
通过这种方式,我可以很快看到自从上次检入后该文件中所做的操作。
>如果你想看看你还没有 git add
ed: git diff myfile.txt
或者如果您想要查看 - 添加
ed修改
git diff --cached myfile.txt
This often happens to me:
I'm working on a couple related changes at the same time over the course of a day or two, and when it's time to commit, I end up forgetting what changed in a specific file. (This is just a personal git repo, so I'm ok with having more than one update in a commit.)
Is there any way to preview the changes between my local file, which is about to be checked in, and the last commit for that file?
Something like:
git diff --changed /myfile.txt
And it would print out something like:
line 23
(last commit): var = 2+2
(current): var = myfunction() + 2
line 149
(last commit): return var
(current): return var / 7
This way, I could quickly see what I had done in that file since it was last checked in.
If you want to see what you haven't git add
ed yet:
git diff myfile.txt
or if you want to see already-add
ed changes
git diff --cached myfile.txt
这篇关于如何在提交之前在git中查看文件差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!