Reputation: 640
I often use git rebase -i <ancestor>
to reorder commits during development to clean up my frequently small commits by grouping related commits together. However my reordering has a tendency to lead to merge conflicts when a later hunk is reordered before an earlier hunk that overlaps.
Is there a way to assess whether conflicts will occur for a particular order before initiating the rebase?
Example:
$ git rebase -i 800adf8
# Interactive Rebase
pick 800adf8 initial commit
pick 2647ae9 content: add header <--+
pick b0a2be6 content: add navbar | hunks overlap
pick 8b86f8a header: add stylesheet <--+
pick 1da6209 content: add footer
pick 7d55152 header: add jquery
pick 515c410 content: add form
# After reorder
pick 800adf8 initial commit
pick 8b86f8a header: add stylesheet <-- conflict
pick 7d55152 header: add jquery
pick 2647ae9 content: add header <-- conflict
pick 1da6209 content: add footer
pick b0a2be6 content: add navbar
pick 515c410 content: add form
Note: I only rebase commits in my local repo that are not pushed to a public repo. I am not looking for advice on best practices.
Upvotes: 4
Views: 267
Reputation: 1323553
Interestingly enough, there was a similar question for mercurial, and the conclusion was similar to torek's comment: you need to simulate the rebase and check if there is any conflict.
This 2010 article had a similar advice:
Review the revision history of master, look for commits likely to contain significant conflicts or representing significant inflection points, and pick your next target commit around them;
if you have a pile of simple commits, you might want the target to be the last such simple commit prior to a big one, for instance.
If you have a bunch of big hairy commits you may want each to be its own target/stage, etc.Use your knowledge of the app.
Upvotes: 1