![]() In this file, the most recent commit is at the bottom.Īs the comment at the bottom of the file explains there are various things I can do, like squashing, dropping and reordering commits. In git log, the most recent commit is at the top. Note that the ordering of commits in the file is opposite the one used for git log. # If you remove a line here THAT COMMIT WILL BE LOST. # These lines can be re-ordered they are executed from top to bottom. # x, exec = run command (the rest of the line) using shell # f, fixup = like "squash", but discard this commit's log message # s, squash = use commit, but meld into previous commit # e, edit = use commit, but stop for amending # r, reword = use commit, but edit the commit message This opens up a file in the default editor with the following contents: pick 7bdfb68 Second commit The command to execute is git rebase -interactive COMMIT-BEFORE-FIRST-COMMIT-WE-WANT-TO-CHANGE, in this case: git rebase -interactive 186d1e0 To do this, I first find the commit before the first commit we want to change. I want to reorder commits 9a24b81 (Third commit) and 7bdfb68 (Second commit). Nothing to commit, working tree git log -oneline Git rebase -interactive is the command you want. These instructions are also provided by the error message printed when the conflict occurs. Otherwise, you'll have to intelligently fix the conflicts (just as you do with merge conflicts), add the fixes, then run git rebase -continue to move on. This could be because you chose a bad order (putting a patch before the commit introducing the feature it patched) in that case you'll want to abort the rebase ( git rebase -abort). ![]() # merge (fast-forward) these into branchBįinally, a disclaimer: It's quite possible to reorder commits in such a way that some no longer apply cleanly. ![]() Git rebase -onto branchB branchA fromAtoB Note that if you had multiple commits you wanted to move between branches, you could use rebase again (non-interactively): # create a temporary branch We should now have: c (branch A) - (dangling commits) Git cherry-pick branchA # cherry-pick one commit, the tip of branchAĪnd the same for a+d+e+g for master: git checkout masterįinally, update branchA so it points to c: git branch -f branchA branchA^^ Now, let's grab the newly-squashed commit b+f for branchB. Now the history should look like this: c - (branchA) Reorder them and tell git to squash the appropriate ones: pick c. Git will present you with a list of the commits in this range. The ^ means the previous commit, so this command says to rebase branch A using the commit before "a" as the base. I'm going to assume you want to leave commit c on branch A, and that you really do mean you want to move the other commits to the other branches, rather than merging, since merges are straightforward. The command you're looking for is git rebase, specifically the -i/-interactive option.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |