Merge two commits where commits are between

I want to combine the two commits - there are commits between the two commits. The commits between do not change the files edited by commit 1 and commit 6. Commits have not yet been pressed.

Is it possible?

f68ffb5 commit 6 ... d294fac commit 1 
+6
source share
3 answers

As I mentioned in my comment. You can do the following:

git rebase -i and reorder the commit as 162345 or 612345 , rather than squaring them together to get a story like (1+6)2345 .

+2
source

you can use git rebase, assuming that commit 1 - 6 commit beahind head:

 git rebase -i HEAD~6 

a git will open a window with 6 commits and explain to you what these options are. You want to combine commit 6 and commit 1, so squash commit 1 in commit 6:

 pick f68ffb5 commit 6 ... squash d294fac commit 1 

another git window will open for editing the commit message.

+1
source

For commits in the same branch

 # make sure you're on the proper branch git checkout branch-with-commits 

This is important: you need to give a reference to commit to the one you want to pass through. Here we make the "before" link with ^ .

 # rebase to the commit before commit 1 git rebase -i d294fac^ 

An editor window will open. This is probably vim, and if you are not familiar with it, check out How to exit the Vim editor?

In this list, commits go in reverse order (not like in git log ): from earliest to last.

Align the lines as follows:

 pick d294fac commit 1 squash f68ffb5 commit 6 pick <sha1> commit 2 pick <sha1> commit 3 pick <sha1> commit 4 pick <sha1> commit 5 # and if there are commits later that commit 6: pick <sha1> commit 7 ... 

Save the document. Git now opens a new editor window to report the new commit 1 & 6. Save it too. The permutation is in progress.

+1
source

Source: https://habr.com/ru/post/988700/


All Articles