Using gitk to view the full history of a moved file

一笑奈何 提交于 2019-12-03 01:28:36

If you want to see the changes that was made in each commit even the file has been renamed, you can use the option -p of git log:

git log -p --follow [file/with/path]

Here's a bash function that should show you the history of a file (using gitk) in all its incarnations ... I'll leave it as an exercise to the reader if they need it for another shell:

# bash
gitk_follow () {
  while (( "$#" )); do
    git log --oneline --name-status --follow $1;
    shift;
  done | perl -ne 'if( s{^(?:[ACDMRTUXB]|R\d+)\s+}{} ) { s{\s+}{\n}g; print; }' | sort -u
}

# used as:
gitk $(gitk_follow some_file)

updated:

Changed to use perl because I didn't pay close enough attention to the output from git log in the last version.

A simpler function using different git log options and awk to exact the file names (and the "--" that gitk needs is included):

# bash
gitk_follow () {
  while (( "$#" )); do
    git log --pretty="" --name-status --follow $1;
    shift;
  done | awk '{print $NF}' | sort -u
}

# used as:
gitk -- $(gitk_follow some_file)

Another alternative is to use the SourceTree application (GUI) developed by Atlassian. Inside the application you can right-click on the file and select "Log Selected ..."

.

In the pop-up window it then allows you to "Follow renamed files":

I also use GitHub for Mac, but didn't see that kind of functionality in there, yet.

(I am not affiliated with either of them!)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!