Finding a Lost Git Commit with the Show-Branch Command
There are various ways we can find “lost” Git commits but I prefer using
show-branch command shows the branch name along with the commit message. You can also add an option to order the branches/commits by date which orders the results by their commit date.
As an example, I created a readme file but could not remember what branch it was on. To locate this commit and its branch, I ran the following
git show-branch --date-order
The result of that command:
! [create-documentation] Create documentation for finding lost git commit ! [create-initial-files] Create initial draft of readme documentation * [master] Merge branch 'create-documentation' --- - [master] Merge branch 'create-documentation' + * [create-documentation] Create documentation for finding lost git commit ++* [create-initial-files] Create initial draft of readme documentation
The above results showed me that I had a commit with the message of “Create initial draft of readme documentation” and it was created in the
create-initial-files branch. This simple command helped me to quickly and cleanly list the commits I’ve made, along with the branch they are on, and find my lost commit.
For more information and options on the
show-branch command, see the Git documentation.
DockYard is a digital product agency offering exceptional user experience, design, full stack engineering, web app development, software, Ember, Elixir, and Phoenix services, consulting, and training.