When I put together a commit with rebase, I caused a petite or mischievous matter. I was advised that "patch should be used to reflect multiple commits at once", but when I googled, many methods of combining with rebase were introduced. I did not understand the difference between these two methods, so I will record it with my own caution.
How to combine multiple commits into a single diff
$ git diff -p <source branch> <derived branch >> a.patch
Outputs the difference between the two branches as a patch file.$ patch --dry-run -p1 < a.patch
$ patch -p1 < a.patch
git add
.$ git diff <source branch> <derived branch> | patch -p1
In this way, you can also execute them all at once on one line.$ git rebase -i HEAD ~ (number of commits going back from HEAD)
Since vim starts up, edit and save the commit message and the sequence of commits.$ git push -f origin <branch>
$ git co --ours(--theirs)
$ git add .
$ git rebase --continue
(continue rebase after conflict resolution)
→ When finished, again $ git push -f origin <branch>
(@Personal branch) $ git merge develop
$ git rebase -i HEAD~Summarize commits with xx
$ git push -f origin <branch>
I took the above steps. What will happen?
... It was bad to use $ git rebase -i HEAD ~ xx
if there was a commit by someone other than yourself between the commits you were trying to put together, as in this case.
Putting it together with $ git rebase -i HEAD ~ xx
, it also recommits other people's commits.
At this time, it will be summarized as your own commit, so you will have committed yourself.
I had to put together only my own commits first and then merge the develop branch.
(See here)
$ git push -f origin <branch>
be careful! !! ** **$ git rebase
.cherry-pick
only for yourself.
→ Can be used as a wipe when you make a mistake in git operation ...$ git reset
, it will be easier to correct if you make a mistake.
→ It is even better if you can be aware of the options --soft
, --hard
, --mixed
.$ git reset HEAD ^
without pushing
(There is a possibility of a lot of conflicts ...)Recommended Posts