-1

I made a contribution to an open source project recently on github and it was well received, but I didn't conform with the commit message standards so I was asked to do so, and instead of doing one change per commit, I should just make one commit with all the changes that I proposed in it.

So, how can I undo all my previous commits and do just one with all the changes in it?

XVirtusX
  • 679
  • 3
  • 11
  • 30
  • 2
    possible duplicate of [Squash my last X commits together using Git](http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git) – Andrew C Dec 02 '14 at 02:26
  • Can you specify whether the owners of the project have already rolled back your commits? If so, you can simply merge your feature branch into the remote. You would then be leaving one commit with one comment. – Tim Biegeleisen Dec 02 '14 at 09:08

1 Answers1

1

You can use a git interactive rebase to "squash" your commits into one.

# To squash 2 commits
git rebase -i HEAD~2

or

# To squash back to a specific commit identified by it's sha1
git rebase -i a3ea79f


If you have a commit history like this:-

git log --oneline --decorate

* d6f7bbd (HEAD, master) added test2
* 35dde7a added test1
* a3ea79f initial commit


Rebasing with either of the rebase commands above will open the editor. It will look something like this and modifying the "pick" lines will adjust the commits:-

pick 35dde7a added test1
pick d6f7bbd added test2

# Rebase a3ea79f..d6f7bbd onto a3ea79f
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Tricky
  • 182
  • 5