0

How can I find file that is or was in all branches by name? I've many remote branches and I want search file by name if file is deleted I want know about it. I don't want download all branches and type git log in each of them.

xrayx
  • 57
  • 7
  • 2
    Possible duplicate of [Git: How to find a deleted file in the project commit history?](https://stackoverflow.com/questions/7203515/git-how-to-find-a-deleted-file-in-the-project-commit-history) – Quentin Sep 19 '19 at 14:45
  • @Quentin I don't want find only deleted files. I want search file and if it doesn't extist in repo I want to know if it was and has been removed – xrayx Sep 19 '19 at 14:59
  • 1
    The first answer over there will list all of the commits where a matching file has been created, modified or deleted. – Quentin Sep 19 '19 at 15:02
  • @Quentin It works only for branch that I've locally. I don't want download more than 30 branches. – xrayx Sep 19 '19 at 15:06
  • 1
    Git *only* works locally, excluding pushing and fetching. Remote operations are only provided by your git server, which you haven't mentioned. – Quentin Sep 19 '19 at 15:10
  • @Rav3 You can search files only in local branches so you have to download commits and related objects. – phd Sep 19 '19 at 15:10

1 Answers1

1
git log --pretty=format:"%d" --diff-filter=D --all -- *filename*

might do the trick for you? (to be run once from any branch, not from each branch like you rightfully want to avoid)

I suggested to output decoartions here (%d) to output branch info rather than just commits, but in the case when your branch doesn't point at the specific commit(s) where the file has been deleted, it won't work.

You'll have to just output its hash (--pretty=format:"%h") then

git branch -a --contains <hashYouFound>

then it'll output every branch which has this commit (where the file has been deleted)

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • What is ```path/to/file```? I don't know where is file which I want find. – xrayx Sep 19 '19 at 14:54
  • @Rav3 Your last comment totally lost me. You'd have to reiterate from the beginning as this is totally different than what your post suggested. "**How can I find file** that is or was in all branches **by name**?" – Romain Valeri Sep 19 '19 at 14:57
  • I want search file and if it doesn't extist in repo I want to know if it was and has been removed. – xrayx Sep 19 '19 at 15:01
  • @Rav3 How will you be searching for it if not by name? By smell? – Romain Valeri Sep 19 '19 at 15:03
  • by name xyz.php for example. I don't know path of file. – xrayx Sep 19 '19 at 15:05
  • Oh I get it! Sorry I'm pretty dense :-) You have the name of the file, just don't know where it is....ok I'm editing ^^ – Romain Valeri Sep 19 '19 at 15:06
  • @Rav3: Note that as far as *Git* is concerned, the file's name *is* the full path: `foo/bar/xyz.php` is a file name. The fact that the file name has slashes isn't all that important. One way to communicate that to people who are "thinking like Git" is to call that the file's *base name*, although the base name of `xyz.php` is also sometimes `xyz` (strip off the extension), so even this is a bit flawed. – torek Sep 19 '19 at 19:44