Visualizing Git: Master Merge, Rebase, Reset, Revert & More
This article uses animated visualizations to clearly explain the core Git commands—merge (fast‑forward and no‑ff), rebase, interactive rebase actions, reset (soft and hard), revert, cherry‑pick, fetch, pull, and reflog—showing how each operation affects branches and history.
Introduction
The author, Lydia Hallie, presents a series of animated GIFs that illustrate the behavior of common Git commands such as git merge , git rebase , git reset , git revert , git fetch , git pull and git reflog . Visualizing these operations helps developers understand how branches interact and how history is modified.
Merge
Git can perform two types of merges: fast‑forward (‑ff) and no‑fast‑forward (‑no‑ff). A fast‑forward merge occurs when the current branch has no extra commits compared to the branch being merged, so Git simply moves the branch pointer without creating a new commit. A no‑ff merge creates a new merging commit when the current branch has diverged, preserving the history of both branches.
Merge Conflicts
When the same line in a file is edited differently on two branches, or one branch deletes a file while the other modifies it, Git cannot automatically decide which change to keep. It presents a conflict, prompting the user to choose the desired version, edit the file, stage the changes, and commit the resolution.
Rebase
Rebasing copies the commits of the current branch onto another branch, producing a linear history without a merge commit. This operation does not create conflicts if the target branch already contains the changes, and it results in a clean, straight‑line commit graph.
Interactive Rebase
Interactive rebase allows developers to edit, reorder, or combine commits before applying them. The six possible actions are:
reword – change the commit message
edit – modify the commit content
squash – combine the commit with the previous one, keeping both messages
fixup – combine the commit with the previous one, discarding its message
exec – run a command on the commit
drop – remove the commit entirely
Reset
Soft reset moves HEAD to a specified commit while leaving the working directory and index untouched, allowing you to keep the changes for a new commit. Hard reset moves HEAD and discards all changes in the working directory and index, restoring the repository to the state of the chosen commit.
Revert
git revertcreates a new commit that undoes the changes introduced by a previous commit, without altering the existing history. This is useful for safely removing unwanted changes while preserving the commit graph.
Cherry‑pick
When a specific commit from another branch is needed, git cherry-pick applies that single commit onto the current branch, creating a new commit that contains only the selected changes.
Fetch
git fetchdownloads new commits and objects from a remote repository without modifying any local branches. It updates the remote‑tracking branches so you can inspect the new data before deciding how to integrate it.
Pull
git pullis a shortcut that performs git fetch followed by git merge, automatically integrating the fetched changes into the current branch.
Reflog
git reflogrecords every movement of HEAD, including merges, resets, and reverts. It allows you to view the history of actions and recover a previous state by resetting HEAD to an earlier reflog entry.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
