View the change history of a file using Git versioning

后端 未结 24 1791
臣服心动
臣服心动 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:16

    If you prefer to stay text-based, you may want to use tig.

    Quick Install:

    • apt-get: # apt-get install tig
    • Homebrew (OS X): $ brew install tig

    Use it to view history on a single file: tig [filename]
    Or browse detailed repo history: tig

    Similar to gitk but text based. Supports colors in terminal!

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

    You can use vscode with GitLens, it's a very powerful tool. After installed GitLens, go to GitLens tab, select FILE HISTORY and you can browse it.

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

    To show what revision and author last modified each line of a file:

    git blame filename
    

    or if you want to use the powerful blame GUI:

    git gui blame filename
    
    0 讨论(0)
  • 2020-11-22 17:22

    Summary of other answers after reading through them and playing a bit:

    The usual command line command would be

    git log --follow --all -p dir/file.c
    

    But you can also use either gitk (gui) or tig (text-ui) to give much more human-readable ways of looking at it.

    gitk --follow --all -p dir/file.c
    
    tig --follow --all -p dir/file.c
    

    Under debian/ubuntu, the install command for these lovely tools is as expected :

    sudo apt-get install gitk tig
    

    And I'm currently using:

    alias gdf='gitk --follow --all -p'
    

    so that I can just type gdf dir to get a focussed history of everything in subdirectory dir.

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

    Lately I discovered tig and found it very useful. There are some cases I'd wish it does A or B but most of the time it's rather neat.

    For your case, tig <filename> might be what you're looking for.

    http://jonas.nitro.dk/tig/

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

    You can use

    git log -p filename
    

    to let git generate the patches for each log entry.

    See

    git help log
    

    for more options - it can actually do a lot of nice things :) To get just the diff for a specific commit you can

    git show HEAD 
    

    or any other revision by identifier. Or use

    gitk
    

    to browse the changes visually.

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