Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git change code from a specific pushed commit on specific branch

I still have some difficulties to understand completely the process to modified an already pushed commit.
I am not working on the master branch (don't know if that matter), and I committed and pushed wrong data (say, clear password...) in the Commit_2 (see below).
I would like to change files from this commit only, and don't change the others.
Of course, I have read the documentation git-rebase, cherry-pick etc.. as well as some very nice answers from SO, like here or here, but I am still not sure how to do it.

So, basically, how can I change files from, and only from Commit_2 ?

commit 54sdf4f4d5f4dsf4555q5aaaa44fr
Author: me <[email protected]>
Date:   Wed Sep 14 10:25:09 2016 +0200

    Commit_3

commit ghgzf4x1522qx1x5f222y4d
Author: me <[email protected]>
Date:   Tue Sep 13 15:01:42 2016 +0200

    Commit_2

commit dfsdc4ycx45ds4fyc6d4fysfsd
Author: me <[email protected]>
Date:   Tue Sep 13 14:57:08 2016 +0200

     Commit_1
like image 952
Mornor Avatar asked Aug 11 '26 15:08

Mornor


1 Answers

I like interactive rebase

git rebase -i ghgzf4x1522qx1x5f222y4d^

Set that commit from pick to e for edit. Then make your changes (delete password). Then continue.

git rebase --continue

Now that you have rewritten history, you will have to force push to the remote.

git push <remote> <branch> --force

And others will need to non-fast-forward pull.

git fetch <remote>
git reset --hard <remote>/<branch>

Or maybe

git pull --rebase
like image 152
Jeff Puckett Avatar answered Aug 14 '26 12:08

Jeff Puckett



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!