4 ms·
If you really want just one commit on your PR you can reset your branch to its target before you merge: git reset --soft <target> Which will undo all commits
by elpakal 4y ago
If you really want just one commit on your PR you can reset your branch to its target before you merge:
git reset --soft <target>
Which will undo all commits and leave all modified files in the staging area. Then you can make one commit and force push it to replace your branch @ remote.
- fbormann 4y agoThanks for the tip, man! Really helpful indeed.
- bern4444 4y agoYou could also rebase and squash all commits into a single one and then rewrite the commit message with git commit --amend.
- xorcist 4y agoOr just git rebase -i like normal people.
- 1ark 4y agoNot sure why downvoted, this is the "correct" way. Can also do --autosquash etc. at the same time.
- elpakal 4y agowhat makes this more correct than the other way? if anything an interactive rebase requires a lot more ceremony
- xorcist 4y agoThrowing away the commit and doing it again can easily go wrong. It is easy to commit unintended changes by mistake. The interactive rebase is a completely normal operation and intended for exactly this situation. It is also much easier to craft more than one commit, and last minute fixes of spelling errors and such things.
- ninkendo 4y agoCareful here… if <target> is not in the ancestry of HEAD, resetting to it may have the effect of undoing any changes that have happened on the <target> branch that aren’t in yours. To be safe, you can do: git reset $(git merge-base <target> HEAD) Which puts HEAD at the last commit in common between your branch and <target>… which, if target is already a parent/ancestor of your commit, is the same thing. But if target has had changed since you branched from it, this prevents you from undoing any recent commits.