Find commit to find a very old deleted file in Azure Devops
Asked Answered
B

3

7

I started working on this project a little over a year ago, and it seems a file is missing from what may be even longer than that. I am trying to go back into my repo to find when this file may have been removed but I do not know what commit let alone the date or user who may have done it.

It seem that in Azure Devops I can only search by name, path, user, date, or by just going thru every commit ever until I find the file lol. I have gone thru the history of the file that contains it but again without knowledge of the date or user or commit, I have no way to find it?

I have tried git commands, something along the lines of

$ git log --all --full-history -- <path-to-file>
$ git log --all --full-history -- **/thefile.*

or stuff I've found here on stack, like

grep -rnw '/path/to/somewhere/' -e 'pattern'

and all the alternate version of that.

These and many commands or routes to find it in the actual Azure Devops backend site that's attached to Visual Studios... just all don't seem to help.

Hoping anyone knew of a way around this or a command to find it? Thanks!

Blackguardly answered 12/1, 2021 at 18:10 Comment(1)
Does this answer your question? How to find and restore a deleted file in a Git repositoryHelicon
B
7

The first command suggested by PieDev works, but the 2nd set of commands did not return any information, they might not be wrong, they just didn't help me specifically.

This solution to a similar post guided me to the following solution:

git log --diff-filter=D --summary | grep -E 'delete|^commit\s+\S+'

this will display all the deleted files AND the commits that pushed the changes.

Blackguardly answered 12/1, 2021 at 20:4 Comment(0)
W
7

What about searching all deleted files?

git log --diff-filter=D --summary | grep delete

Show history on that file (or what you have in your original post)

git log --all -- DeletedFilePath
git show COMMIT_ID -- DeletedFilePath
Weathertight answered 12/1, 2021 at 18:50 Comment(2)
The command for searching deleted files works, in the sense that I do see the deleted file, but ur second commands there to show the history on that file does not seem to work. for instance, the command to see all deleted files produces delete mode 100644 Mvc/Controllers/CarouselController.cs but when trying to input $ git log --all -- Mvc/Controllers/CarouselController.cs it produces nothing and simply goes back into a ready state for the next command.Blackguardly
I ended up using git log --diff-filter=D --summary | grep -E 'delete|^commit\s+\S+' to not only show all the files but the respective commits as well. Thank you for your help!Blackguardly
B
7

The first command suggested by PieDev works, but the 2nd set of commands did not return any information, they might not be wrong, they just didn't help me specifically.

This solution to a similar post guided me to the following solution:

git log --diff-filter=D --summary | grep -E 'delete|^commit\s+\S+'

this will display all the deleted files AND the commits that pushed the changes.

Blackguardly answered 12/1, 2021 at 20:4 Comment(0)
O
0

There's an easy way to do this through Visual Studio, but it requires some knowledge (or guess) of when the file may have existed:

  1. Pull up the project history (Git --> View Branch History).
  2. Locate any commit where you believe the file may have existed.
  3. While holding down the Ctrl key, click that commit and the latest commit so that both are selected.
  4. Right-click one of those commits and select Compare Commits...

If your commit selection in step 2 was in range of when the file existed, the resulting compare window will show the now-deleted file with a strikethrough. Right-click it and select View History. The top commit in the history is the one where the file was deleted. At that point you can view the commit details or do whatever else you want to do with the commit.

Obtuse answered 23/2 at 21:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.