git – How do I change an old commit?


I am learning git while working on an application.
At the moment I have a master branch and another hotfix branch.
While working on the hotfix branch, I noticed that in one of the previous commits, I forgot to add some data to one of the files.
You can, of course, add them now, and just make a commit with these changes, but for purposes of study, I would like to change the old commit in which this file was added.
Final goal:

  1. modified a file that was added in an old commit
  2. this file, in modified form, was added to this old commit
  3. in all subsequent commits in this branch, the changes are visible
  4. pushed to github

How to work properly in such a situation?


To change NOT the last commit, run:

git rebase --interactive 

Source .

Scroll to Top