Piyush Chaudhary
Piyush Chaudhary

Reputation: 313

Amend previous commit with no change to commit message

I had already pushed some changes to a remote. Now I need to push some other changes which should be in that previously pushed commit but somehow are not. I can do this simply by pushing the changes with a new commit but just now I have found the --no-edit flag and --amend

If I need to push the new changes but I need a single commit having the old and new changes is git commit --amend --no-edit going to achieve that?

Upvotes: 1

Views: 9242

Answers (2)

Piyush Chaudhary
Piyush Chaudhary

Reputation: 313

Yes, the git commit --amend --no-edit is the thing that I am looking for.

  1. git add . (Add the added and modified files)
  2. git commit --amend --no-edit
  3. git push --force-with-lease <remote> <branch>

Upvotes: 6

Anders Lundb&#228;ck
Anders Lundb&#228;ck

Reputation: 98

Generally, it's best to avoid rewriting the history, and just add a new commit as hyde suggested.

If you really need to overwrite the history, make sure to use --force-with-lease when you push.

Upvotes: 3

Related Questions