Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new changes to any commit

Tags:

git

Sometimes when I have done some changes (git diff) I want part of them (only particular files) add to older commit.

What is the easiest way to do it?

like image 380
Marcin Avatar asked Jun 07 '26 16:06

Marcin


1 Answers

You could add the changes you would like to merge in an older commit like this

git add [path] or git add -p

then create a fixup commit with the hash of the commit you would like to move those changes

an example:

git commit --fixup [commit hash]

To merge these 2 commits into 1 you will finally need to do interactive rebase

git rebase -i origin/[branch name] --autosquash

Be ware that you have to force push (with caution) after an interactive rebase

git push -f

like image 136
Vangel Tzo Avatar answered Jun 09 '26 08:06

Vangel Tzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!