How do I find a particular file in all branches?

Asked

Viewed 384 times

2

First search: I need to find a branch or commit that has a file that was lost... but I have multiple branches and multiple commits in each of these branches...

The file created would be called: projecs/web-sistema/js/add-script-android-platform.js, there is some command or way to track this file within the entire GIT structure, without having to open each branch and keep looking for each commit on https://dev.azure.com/?

details: the branches are more or less like this: feature/sprint_1/create-platform, feature/sprint_2/modify-platform ...

Second search: Maybe this file is not in the project, it may have been created by the mapping of Gulp, what I would have to find then would be all the logs of gulpfile.js that have this mapping internally.

I know if I do this, I’ll have all the file logs: git log gulfile.js

But you would have to filter it just where the path continuation might have this nomenclature:

'add-script-android-platform.js'

I tried to these commands but none worked.

  • You remember the name and path of the file?

  • This: projecs/web-system/js/add-script-android-Platform.js, I just don’t know the branch or the commit. , the file is mapped to the HTML header, but is not in the project. Probably, this branch was not merged with master. I need to locate him.

  • And you don’t remember any branch that might have deleted this file?

  • I’m suspicious that it has another name mapped in Gulp, and it was generated with that name, and I probably have to look for that mapping inside gulpfile.js that is modified in a branch that I don’t know what is.

2 answers

2

What you need to do first is find which commit deleted that file, for that, just use the following command:

git log --all --diff-filter=D -- <seu_arquivo>

This will give you all the commits that deleted this file. To find out which branch contains that commit, just use:

git branch -a --contains <hash_do_commit>

From there, to restore the file, just do a git checkout for the commit.

  • I used the command, found nothing, I’m suspicious that is mapped in Gulp even. But I liked the command...

  • @Ivanferrer then either the file was not versioned by git (in case it was in .gitignore) or it was not deleted in any branch...

  • I figured out the commit, now I wanted to take the branch from that commit.

1


As I solved the problem, I used the following command:

git log gulpfile.js

Then I was reading the commit messages, and checking out the commits:

Example: git checkout 374124d1

And seeing if the files appeared in the project root, in the folder "js", until it appeared in the list. I found in the third checkout. So I went into Azure and I looked for the ID:

I found the commit: 374124d106ce81f8da0bb625b77273d7148cd770

Browser other questions tagged

You are not signed in. Login or sign up in order to post.