5

Sometimes I forget to add some files before commiting. With Mercurial I fix it this way:

  1. hg qinit
  2. Convert commit to patch
  3. Update patch
  4. Convert patch to commit

Can I do anything like this with Git?

  • In theory, you can override history locally: - copy current content - revert to previous version - add all you need - commit new commit as a new head But... personally, I prefer to add another commit. – Vladimir M Sep 18 '16 at 13:07
  • http://stackoverflow.com/a/37848143/828193 – user000001 Sep 18 '16 at 13:09
  • There is no difference between changing a commit message and changing a commit files. Both operations changes a commit. What's changed is just a detail. – Łukasz Rogalski Sep 18 '16 at 13:10
  • Incidentally, there's a shorter way to do this in Mercurial. Just add and commit the file and then run `hg histedit`. You will be given the opportunity to `fold` (Git calls this `squash`) two commits into one new, different commit. See https://www.mercurial-scm.org/wiki/HisteditExtension for details. – torek Sep 18 '16 at 19:55

1 Answers1

2

You are basically trying to change your last commit in Git. This is possible and quite simple.

git commit --amend is used for this purpose.

The following page gives a detailed example.

https://github.com/abhikp/git-test/wiki/Changing-your-last-commit

Ujjwal
  • 1,849
  • 2
  • 17
  • 37