Git Search, Commit History, & Move/Rename Commands [Cheatsheet]

Luka
2 min readMar 8, 2020

No matter how small your codebase is, you’ll often need to find where a function is called or defined, or display the history of a method, especially when codebase grows. Git provides a couple of useful tools for looking through the code and commits stored in its database quickly and easily. I will try to go through some of the useful commands that are used to not only search but find, view and commit history.

Search

A text search on all files in the directory:

$ git grep "Hello"

In any version of a text search:

$ git grep "Hello" v2.5

Commit History

Show all commits, starting with newest (it’ll show the hash, author information, date of commit and title of the commit):

$ git log

Show all the commits(it’ll show just the commit hash and the commit message):

$ git log --oneline

Show all commits of a specific user:

$ git log --author="username"

Show changes over time for a specific file:

$ git log -p <file>

Display commits that are present only in remote/branch in right side

$ git log --oneline <origin/master>..<remote/master> --left-right

Who changed, what and when in <file>:

$ git blame <file>

Show Reference log:

$ git reflog show

Delete Reference log:

$ git reflog delete

--

--

Luka

Software Engineer with a focus on building interactive and impactful applications. JS, React, Ruby on Rails.