Using emacs (and magit?) to visit a file in given commit/branch/etc

前端 未结 4 1556
无人及你
无人及你 2021-01-30 22:34

If I want to see how foo.bar looked like in some certain commit then I can invoke:

git show :foo.bar         


        
4条回答
  •  伪装坚强ぢ
    2021-01-30 23:06

    There's a package called git-timemachine that makes the process of viewing previous versions of a file almost completely seamless; see the link for installation instructions and a demo. (If you are already using MELPA, just do M-x package-install RET git-timemachine RET).

    The way it works is, you call M-x git-timemachine RET from a buffer visiting a tracked file. Then you can:

    • p Visit previous historic version
    • n Visit next historic version
    • w Copy the abbreviated hash of the current historic version
    • W Copy the full hash of the current historic version
    • q Exit the time machine.

    Note that if you know the hash of the commit you want to visit, the custom command from @phils' solution will serve you better for that specific use case. But for navigating between different versions of a file I find that using git-timemachine is even easier than using the functionality that VC provides.

    You can of course bind git-timemachine to a key binding of your choice.

提交回复
热议问题