Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Check file's git history even if renamed/moved
Georgios Kampitakis
Georgios Kampitakis

Posted on • Edited on

     

Check file's git history even if renamed/moved

From time to time, I find myself that I want to rename or move a file to a different folder, but I am reluctant. The reason is thegit history of a file is more important than you might think, so moving it or renaming it, will mean you are going to lose the file history.

How to check a file history even if renamed/moved

git has a really useful flag that can help us.

You can check a file's history withgit log and pass the--follow flag.

In practise for a projectgo-snaps, if you run

# passing --pretty=oneline for brevity git log --pretty=oneline internal/test/test.go
Enter fullscreen modeExit fullscreen mode

will show

<sha-id> chore: add examples for MatchJSON<sha-id> feat: implement MatchJSON snapshot function (#49)
Enter fullscreen modeExit fullscreen mode

but running with the--follow flag

git log --pretty=oneline --follow internal/test/test.go
Enter fullscreen modeExit fullscreen mode

will result in

<sha-id>  chore: add examples for MatchJSON<sha-id>  feat: implement MatchJSON snapshot function (#49)<sha-id>  chore: change file structure<sha-id>  fix: update deps and add more tests (#39)
Enter fullscreen modeExit fullscreen mode

There can be more things before moving a file as you can see in this example.

Why file history can be important you ask

In a commit ( or a series of commits ) there can be a lot of information that can explain decisions that were taken and why the code has evolved as it is right now. This information can be as valuable as the code itself so you can understand why I find--follow useful.


That was my TIL 😃

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Just a curious individual trying to understand how things work (or break 🙃)
  • Location
    London
  • Education
    Bachelor's Degree in Computer Science
  • Work
    Software Engineer at Datadog
  • Joined

More fromGeorgios Kampitakis

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp