Once upon a time, I got into trouble because the commit history of a repository clearly showed that I was working on feature Y before feature X, contrary to the project plan. In fact, you really ought to update the commit message in such cases so that it’s clear to everyone what the commit now contains. Rewording commit messages is also useful after you’ve added staged changes to an existing commit. A window will pop into view where you can tweak or completely replace the commit message. Rewording commit messages lets you tell the story in a way that your colleagues (and your future self) will be able to make sense of.ĭouble-click on the “Description” column in the interactive rebase screen. When you’re in the middle of solving a problem, you don’t know how the whole story will read. When rebasing continues, it will drop back out to Sourcetree, allowing you to do whatever the heck you want before continuing on. To use this feature, check the “Amend commit?” checkbox on the commit you’d like to edit. But the git commit – -amend command lets you do things like change the commit message or add staged changes to a previous commit. Or, you can use the squash with previous option by right-clicking or using the button at the bottom of the dialog. To use the squashing feature in Sourcetree, drag and drop rows on top of one another. Squashing lets you combine tiny-yet-related commits into a single, meaningful commit. Panic commits tend to be small and, taken in isolation, rather trivial. Squashing is a nice way to tidy up after a series of “panic commits” – when you write a line of code, then are overcome by fear of a sudden widespread power shortage resulting in the loss of your work. ex.From there, you’ll have the chance to rewrite your repository’s history with the help of a few operations. git rebase -s ours -preserve-merges origin/masterģ) make note of the SHA. ex.: c4a924d458ea0629c0d694f1b9e9576a3ecf506b git log -1Ģ) Create the proper history but this will break the merge. While I merge the secondary branch into the main branch, work continues in the main branch and by the time i'm done, I can't push my changes because they are incompatible.ġ) make note of the SHA. There is a main branch and a secondary branch if you which. ![]() We have a large code base and we have to deal with 2 branch heavily being modified at the same time. Given that I just lost a day trying to figure this out and actually found a solution with the help of a coworker, I thought I should chime in. In the end we will have this state (note another id of top commit): * 13e6d03 Merge branch 'topic' Then we use commit -amend to rewrite our merge commit, that used to have the incorrect index, with our good index from master. We use reset -soft to reset our branch (and history) to correct-history, but leave index and working tree as is. The last stage is to combine our branch with correct history and branch with correct index git reset -soft correct-history ![]() History will looks like this (ignoring correct-history): * 94f1484 Merge branch 'origin/master' We may get some additional merge conflicts here, but that would only be conflicts from files changed between 8101fe3 and f5a7ca8, it doesn't include already resolved conflicts from topic Git merge origin/master # merge origin/master on top of our master git checkout master # return to our master branch The history will look like this (ignoring master): * 51984c7 Merge branch 'topic' We use -strategy=ours to ignore all merge conflicts as we don't care about what contents will be in that merged commit, we only need a nice history. We use -preserve-merges to save our merge commit in history. Git rebase -strategy=ours -preserve-merges origin/master Note that we have 2 commits ahead of master, so cherry-picking won't work.įirst of all, let's create the correct history: git checkout -b correct-history # create new branch to save master for future We'll start in the same state found in the original question: * 8101fe3 Merge branch 'topic' My solution is based on the idea by B but with exact step-by-step commands Ok, it's an old question and it already has an accepted answer by but that answer wasn't enough in my case, as -preserve-merges forces you to resolve all conflicts a second time. ![]() Is there a clean way to rebase the merge commit so I end up with a history like the one I show below? * 51984c7 Merge branch 'topic' If I try git rebase origin/master from master, I'm forced to resolve all conflicts again, and I also lose the merge commit: * d4de423 2 Now, the merge took me some time, so I do another fetch and notice that the remote master branch has new changes: * 8101fe3 Merge branch 'topic' I perform the merge from master, resolve the conflicts and now I have: * 8101fe3 Merge branch 'topic' I have some work in a topic branch and now I'm ready to merge back to master: * eb3b733 3
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |