VOOZH about

URL: https://www.javacodegeeks.com/2018/04/git-commit-fixup-and-autosquash.html

⇱ Git commit fixup and autosquash - Java Code Geeks


Git commit fixup and autosquash are helpful features when you want to “fix” changes from a single commit in your history.

If you discover that you want to change a single commit in your Git history, you would need to manually commit based on the commit you’re about to change and perform a git rebase. Fixup commits produce commits that fix a specific commit in history by appending a commit with message fixup!. An interactive rebase with --autosquash option will then merge the original commit and the fixup into a new commit and rebase the subsequent commits.

See the following history as an example:

3320dec (HEAD) commit 4
03c9685 commit 3
041c401 commit 2
981fffd commit 1
22f759b (tag: base) initial commit

We can modify changes introduced in 981fffd commit 1 and add them as a fixup commit via git commit -a --fixup 981fffd:

c24491b (HEAD) fixup! commit 1
3320dec commit 4
03c9685 commit 3
041c401 commit 2
981fffd commit 1
22f759b (tag: base) initial commit

In order to clean-up the history we interactively rebase our changes with git rebase --autosquash --interactive base. This will produce a clean history again:

caeb1d8 (HEAD) commit 4
2f6d4da commit 3
8207cf2 commit 2
551ef47 commit 1
22f759b (tag: base) initial commit

The commit hashes after 22f759b now have been changed — they’re based on different commits.

To avoid breaking the history of colleagues you should only change the branch’s history, e.g. via rebase, if the commits haven’t been pushed yet, or if you’re working on a dedicated remote branch.

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Git commit fixup and autosquash

Opinions expressed by Java Code Geeks contributors are their own.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
Git
👁 Photo of Sebastian Daschner
Sebastian Daschner
April 23rd, 2018Last Updated: April 23rd, 2018
0 300 1 minute read

Sebastian Daschner

Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz