Skip to content

Latest commit

 

History

History
94 lines (69 loc) · 3.06 KB

history.md

File metadata and controls

94 lines (69 loc) · 3.06 KB

Git History

Understanding your project's history is essential for debugging regressions and reviewing changes. These commands let you peek back in time.

View changes for a specific commit

This command shows you the exact diff and metadata (author, date, message) for a specific commit. The interactive prompt shows you the last 50 commits to choose from.

git show $commit

Diff two commits

If you need to see all the changes that happened between two different points in time, you can diff two commits directly. This is extremely useful for seeing everything that changed in a release.

git diff $commit_base $commit_target

Interactive Rebase

Interactive rebasing lets you rewrite history. You can squash multiple commits together, drop bad commits, or edit old commit messages. Pick the earliest commit you want to modify, and Git will open an editor to let you rewrite the history that follows it.

git rebase -i $commit_base~1

View who changed what in a file

If you find a bug in a specific line of code and need to know who wrote it (or when it was introduced), git blame annotates every line of a file with its originating commit.

git blame $tracked_file

Cherry-pick a commit

Apply the changes introduced by an existing commit directly to your current branch. #copy-commit #port #steal

git cherry-pick $commit

Revert a commit

Create a new commit that undoes all of the changes made in a previous commit, without rewriting history. #undo-pushed #reverse

git revert $commit

Commit count by author

Summarize the repository history by showing how many commits each author has made. #leaderboard #stats #authors

git shortlog -sn

Export repository to archive

Creates a zip or tar archive of the repository at a specific commit. #zip #tar #export #backup

git archive --format=zip --output=$file_name $commit