Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: View full git commit history (including renames)

I'm using Visual Studio 2015 and the Microsoft Git client. I'm running into some problems with viewing history and annotations with the tooling because Visual Studio doesn't seem to handle file renames when viewing git history. Is there any good way around this?

BTW: I tried using the "Show Full History" toolbutton in the history viewer, but it still didn't actually show history with renames

Here's what I did to test:

  1. In Visual Studio, I right-clicked the file and selected "View History". (it only showed 4 commits)
  2. In the History Window, I clicked "Show Full History" -- still the same 4 commits.
  3. From the git command line, I ran git log --follow TheFile.cs (it produced 13 commits)
  4. In Atlassian Source Tree, I pulled of the log for the file, and I checked the "Follow Renamed Files" option. It pulled the same 13 commits as the command line.

What I really want is to have an option in Visual Studio that would match. Is that possible?

like image 866
JMarsch Avatar asked Sep 21 '15 18:09

JMarsch


People also ask

How do I view commit history in Visual Studio?

Right-click the file in Solution Explorer and select View History. The Visual Studio History view will appear, showing the commits in your repo that updated the file. You can filter the commits to find the exact commit with the file version you want to restore. Double click on the version to open it in Visual Studio.

How do I see my entire git history?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

How do I show previous changes made with commit message?

Looking up changes for a specific commit If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .

How do I view the contents of a commit?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.


1 Answers

Visual Studio does follow history between two commits to determine if a file is renamed. Here, I've renamed a single file from its original name to renamed, and made a change to the contents at the same time:

File History

However, Git does not track changes between two commits - instead, it compares the snapshots of the commits to determine how files have changed. Thus, there is no rename information in the repository's history. Instead, this is calculated by comparing the file in the original commit to the file in the subsequent commit. If they are sufficiently similar, then Git will deem this a rename.

Since this is a heuristic, it's not guaranteed that this will be deemed to be a rename. However, Visual Studio and Git for Windows should agree on these things, generally speaking. I'd be curious why one reports this as a rename and the other does not. There are two possibilities:

  1. This file is very near the edge of similarity - say, Git has decided that the two revisions are 61% similar to each other and are thus a rename, while Visual Studio has decided that the two revisions are merely 59% similar, and thus are not a rename.
  2. There's some bug here where Visual Studio is not calculating the similarity correctly. If I had to guess, I would guess that there's a whitespace or line ending issue, because that's always a problem in Git.

If you're able to share the two revisions of this file, opening a connect bug or emailing them to me directly would help investigate further.

like image 87
Edward Thomson Avatar answered Oct 08 '22 21:10

Edward Thomson