Looking into git rebase and how it looks in the commit history

Looking into git rebase and how it looks in the commit history

Let’s look into a practice so we can see how it works and affects the commit history

1. Let's create two branches off master
2. In feature-one, you:
  • Commit a change to an existing file (let’s call it file.txt).
  • Create a new file called feature-one.txt.

3. In feature-two, you:
  • Commit a change to the same existing file (file.txt).
  • Create a new file called feature-two.txt.

Rebase feature-one onto master
4. Switch to master and rebase feature-one

Now, the commit history on master will look like this:

Rebase feature-two onto master
5. Switch to master and rebase feature-two:
Resolve the Merge Conflict
Resolve the conflict in file.txt, then continue the rebase:
Final Commit History

After resolving the conflict and completing the rebase, the commit history on master will look like this:

Summary
  • git rebase feature-one: This replays the commits from feature-one onto master, making it look like feature-one changes were made directly on top of master.
  • git rebase feature-two: This replays the commits from feature-two onto master after the feature-one changes, requiring conflict resolution if both branches modified the same lines in the same files.
No Comments

Post A Comment