简体   繁体   中英

How to view the git diff on a file?

I cloned a git project into a folder on my desktop. I want to see the changes made on a certain file throughout its lifetime. I tried the

git log -- <filename>

command, yet this did not produce any output. I'm guessing that cloning a project does not necessarily clone the history as well? I can go on github and somewhat view the changes made to a file in a certain revision (yet this is polluted with the changes made in other files also). If anyone can give me point me in a general direction that would be great.

Cloning a repository copies the entire history all the way back to the first commit.

One way to get there at the risk of overwhelming yourself with lots of detail from various contexts is

git log --all -- filename

To see the changes (or patches or deltas) made with each commit, run

git log --all --patch -- filename

When viewing patches, I generally do not want to see clutter from whitespace-only changes, so I run

git log --all --patch --ignore-all-space -- filename

To save a bit of typing, the above command is equivalent to

git log --all -p -w -- filename

Because of --all , this may show much more than you care about and will leave you to puzzle out which changes belong to which branch. To narrow it down, you can look at changes on a particular branch with

git log -p -w my-branch -- filename

or possibly a commit range as in

git log -p -w origin/master..master -- filename

You do not necessarily have to switch branches because git log has access to the entire repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM