Git show whole file changes

假如想象 提交于 2019-12-10 10:14:36

问题


Is there a way to get the git show command to show the whole contents of a file when viewing a commit? For example: if it currently show something like

foo.cpp

+++ int main() {
+++    std::cout << "HELLO" << std::endl;
+++ }

I would want the output to say:

foo.cpp

#include <stdio> //assuming this was from an earlier commit

+++ int main() {
+++    std::cout << "HELLO" << std::endl;
+++ }

Is there a simple way to do this?


回答1:


This is kind of a hack, but git show (like git diff) has the -U option that lets you specify how many lines of context to show. If you use a number that's bigger than the region between the difference and the start or end of the file, then it'll show the whole file. So if you use a really big number, it'll work the way you want on (hopefully) any file you try it on:

git show -U99999



回答2:


This command show whole file:

git show HEAD:./<path_to_file>

And it works also for any revision:

git show <rev-id>:./<path_to_file>


来源:https://stackoverflow.com/questions/27238258/git-show-whole-file-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!