View the change history of a file using Git versioning

后端 未结 24 1792
臣服心动
臣服心动 2020-11-22 16:40

How can I view the change history of an individual file in Git, complete details with what has changed?

I have got as far as:

git log -- [filename]
         


        
相关标签:
24条回答
  • 2020-11-22 17:28

    The answer I was looking for that wasn't in this thread is to see changes in files that I'd staged for commit. i.e.

    git diff --cached
    
    0 讨论(0)
  • 2020-11-22 17:29

    Add this alias to your .gitconfig:

    [alias]
        lg = log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\n--abbrev-commit --date=relative
    

    And use the command like this:

    > git lg
    > git lg -- filename
    

    The output will look almost exactly the same as the gitk output. Enjoy.

    0 讨论(0)
  • 2020-11-22 17:29

    If you're using the git GUI (on Windows) under the Repository menu you can use "Visualize master's History". Highlight a commit in the top pane and a file in the lower right and you'll see the diff for that commit in the lower left.

    0 讨论(0)
  • 2020-11-22 17:29

    If you use TortoiseGit you should be able to right click on the file and do TortoiseGit --> Show Log. In the window that pops up, make sure:

    • 'Show Whole Project' option is not checked.

    • 'All Branches' option is checked.

    0 讨论(0)
  • 2020-11-22 17:29

    If you are using eclipse with the git plugin, it has an excellent comparison view with history. Right click the file and select "compare with"=> "history"

    0 讨论(0)
  • 2020-11-22 17:30

    git diff -U <filename> give you a unified diff.

    It should be colored on red and green. If it's not, run: git config color.ui auto first.

    0 讨论(0)
提交回复
热议问题