ryanjang-devnotes
Published in

ryanjang-devnotes

[Git] Git Essentials — 1. Merge & Rebase

Merge

Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means “I want to include all the work from this parent over here and this one over here, and the set of all their parents”

Rebase

git rebase [onto the branch name]

Rebasing essentially takes a set of commits, “copies” them, and plops them down somewhere else. The advantage of rebasing is that it can be used to make a nice linear sequence of commits. The commit history of the repository will be a lot cleaner if only rebasing is allowed.

Note that the commit C2 still exists somewhere, and C2' is the copy that we rebased onto main. The only problem is that main hasn’t been updated either. We need to be checked out on the main branch and rebase onto bugFix .

Moving around in Git

HEAD

HEAD is the symbolic name for the currently checked out commit — it’s essentially what commit you’re working on top of. HEAD always points to the most recent commit which is reflected in the working tree. Normally HEAD points to a branch name.

Detaching HEAD just means attaching it to a commit instead of a branch. However, moving around in Git by specifying commit hashes can get a bit tedious since the hash of the commit is fed2da64c0efc5893610bdd892f82a in the real world. That’s why Git has relative refs. With relative refs, you can move upwards one commit at a time with ^ and a number of times with ~<num> .

Reference

https://learngitbranching.js.org/?locale=en_US

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Minho Jang

Minho Jang

Backend Developer, Writer, and Lifelong Learner