View the change history of a file using Git versioning

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

    In Sourcetree UI (https://www.sourcetreeapp.com/), you can find history of a file by selecting 'Log Selected' option in right click context menu:

    It would show the history of all the commits.

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

    I wrote git-playback for this exact purpose

    pip install git-playback
    git playback [filename]
    

    This has the benefit of both displaying the results in the command line (like git log -p) while also letting you step through each commit using the arrow keys (like gitk).

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

    SourceTree users

    If you use SourceTree to visualize your repository (it's free and quite good) you can right click a file and select Log Selected

    enter image description here

    The display (below) is much friendlier than gitk and most the other options listed. Unfortunately (at this time) there is no easy way to launch this view from the command line — SourceTree's CLI currently just opens repos.

    enter image description here

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

    If you want to see the whole history of a file, including on all other branches use:

    gitk --all <filename>
    
    0 讨论(0)
  • 2020-11-22 17:32

    With the excellent Git Extensions, you go to a point in the history where the file still existed (if it have been deleted, otherwise just go to HEAD), switch to the File tree tab, right-click on the file and choose File history.

    By default, it follows the file through the renames, and the Blame tab allows to see the name at a given revision.

    It has some minor gotchas, like showing fatal: Not a valid object name in the View tab when clicking on the deletion revision, but I can live with that. :-)

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

    You can also try this which lists the commits that has changed a specific part of a file (Implemented in Git 1.8.4).

    Result returned would be the list of commits that modified this particular part. Command :

    git log --pretty=short -u -L <upperLimit>,<lowerLimit>:<path_to_filename>
    

    where upperLimit is the start_line_number and lowerLimit is the ending_line_number of the file.

    More details at https://www.techpurohit.com/list-some-useful-git-commands

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