I am experimenting with Git. I have a file a.txt in the repo and 4 commits in my master branch currently. git log:
* aabe7d0 (HEAD -> master, origin/master, origin/HEAD) Updated goats
* 57694cf (tag: customerY_release) Updated sheep
* 791b4cb (tag: customerX_release) Updated cows
* e96a52b Added init contents..'
I want to amend an older commit ie., change a line in file a.txt in the commit 791b4cb. "cats=10" to "cats=100". This change then should reflect across all commits 791b4cb, 57694cf, aabe7d0 and no new commits should be created in the process, the tree should look same at the end.
I tried the following from reference: https://stackoverflow.com/questions/8824971/how-to-amend-older-git-commit:
git rebase -i HEAD~3 // HEAD~2 did not list the commit 791b4cb...
Then changed the line in the opened text editor to:
edit 791b4cb
pick 57694cf
pick aabe7d0
Saved... and then made the required changes in a.txt "cats=10" to "cats=100"... and then commited.
git add a.txt
git commit --amend --no-edit
git rebase --continue
But the above process resulted in a different looking tree with new commits added.
* f55fdd4 (HEAD -> master) Updated goats
* 59c850d Updated sheep
* 7aee3ea Updated cows
| * aabe7d0 (origin/master, origin/HEAD) Updated goats
| * 57694cf (tag: customerY_release) Updated sheep
| * 791b4cb (tag: customerX_release) Updated cows
|/
* e96a52b Added init contents..'
This is not what I intended. I wanted the tree looks same as from beginning as if all existing commits: 791b4cb, 57694cf, aabe7d0 get merged and amended across with changes happened in a.txt at 791b4cb... Is it possible to do this in Git?