How to Flatten git Commits

One of my least favorite tasks as a software engineer is resolving merge conflicts. A simple rebase is a frequent occurrence but the rare massive conflict is inevitable when many engineers work in a single codebase. One thing that helps me deal with large rebases with many merge conflicts is flattening a branch’s commits before […]

The post How to Flatten git Commits appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

One of my least favorite tasks as a software engineer is resolving merge conflicts. A simple rebase is a frequent occurrence but the rare massive conflict is inevitable when many engineers work in a single codebase. One thing that helps me deal with large rebases with many merge conflicts is flattening a branch’s commits before fixing merge conflicts. Let’s have a look at how to flatten those commits before resolving those conflicts!

My typical command for rebasing off of the main branch is:

# While on the feature branch...
git rebase -i master

To flatten commits before the rebase, which can make resolving merge conflicts easier, you can slightly modify the original command:

# While on the feature branch...
# git rebase -i HEAD~[NUMBER_OF_COMMITS]
git rebase -i HEAD~10

The example above would flatten the last 10 commits on the branch. With just one single commit, you avoid the stop-start nature of fixing merge conflicts with multiple commits!

The post How to Flatten git Commits appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2022-01-07T02:05:04+00:00) How to Flatten git Commits. Retrieved from https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/

MLA
" » How to Flatten git Commits." David Walsh | Sciencx - Friday January 7, 2022, https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/
HARVARD
David Walsh | Sciencx Friday January 7, 2022 » How to Flatten git Commits., viewed ,<https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/>
VANCOUVER
David Walsh | Sciencx - » How to Flatten git Commits. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/
CHICAGO
" » How to Flatten git Commits." David Walsh | Sciencx - Accessed . https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/
IEEE
" » How to Flatten git Commits." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/. [Accessed: ]
rf:citation
» How to Flatten git Commits | David Walsh | Sciencx | https://www.scien.cx/2022/01/07/how-to-flatten-git-commits/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.