Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forgot branch name where code was committed

Tags:

git

I am working in a repository that contains hundreds of branches and dozens of active developers.

Yesterday, to resolve an urgent problem, I committed my work to my branch (called feature/new-foo), fixed something in a new branch off master (after git fetch), and went home.

This morning, I forgot what my feature/new-foo branch was called.

I have tried the following:

  • git log --all, which shows all recent commits from all branches, to no avail
  • git branch -v | grep "foo", which searched for all branches with the word foo in it; no good results were found.
  • git for-each-ref --sort=-committerdate refs/heads/, which sorts all branches by commit date; still nothing
  • git stash list, just in case, and my changes weren't there either.

All I remember from my work was the addition of keywords class Edge.

Are there any commands I should try, or is my feature commit forever lost in the sea of branches and commits?


This is not related to: this problem

like image 590
Brian Avatar asked Mar 19 '23 00:03

Brian


2 Answers

If you want to use the keywords you added to look for the branch, you could check the commit logs of each branch:

git log --oneline -S "class Edge" --source --all

This will list references of all commits that introduced or removed the string "class Edge".

like image 168
cmbuckley Avatar answered Apr 29 '23 02:04

cmbuckley


Assuming that there haven't been a lot of commits, you could run this command to order your branches by last commit. At least then, you can see which branches you've committed to recently to try to figure out which one it might be.

# How can I get a list of git branches, ordered by most recent commit?
# http://stackoverflow.com/q/5188320/165988
git for-each-ref --sort=-committerdate refs/heads/
like image 37
NT3RP Avatar answered Apr 29 '23 02:04

NT3RP