0

Here's the scenario: I've made a substantial number of changes to my project so I add, commit, and am ready to push. Then, right before pushing, I remember that I need to change 1 line of the README.

I would like to not have to make a separate commit just for the README edit. Is there any way to either

A. Add to the commit I already have

B. Remove the previous commit, combine everything into one commit

This happens fairly often, and I've always just made two commits, but having just one would be great!

goodcow
  • 4,495
  • 6
  • 33
  • 52
  • For undoing a commit, see [Revert to a previous Git commit](http://stackoverflow.com/q/4114095/456814). –  Aug 08 '14 at 22:07

2 Answers2

1

This would be (after making your change and adding it to the index) a

git commit --amend

If you don't want to change the comment:

git commit --amend --no-edit

From git commit man page:

--amend

Replace the tip of the current branch by creating a new commit.

See Git A Visual Guide:

https://julianscorner.com/wiki/_media/programming/git/commit-amend.png

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0
git add README

git commit --amend

How to modify existing, unpushed commits?

http://git-scm.com/book/en/Git-Tools-Rewriting-History

Community
  • 1
  • 1
poof
  • 69
  • 5