I have a branch called develop
in which I am at commit c08e2887
. I have to go back to an old commit 6a73b96e
, make some changes to that old commit, commit again (let's call it abc
) and push it to my remote branch develop
. Later on, I will need to go back to my (current) commit c08e2887
both locally and remotely.
The remote branch to which I push the commit abc
should have the same name develop
, it cannot be a different one because I need to run some other process which depends on it.
What is the best way to do this?
Alternatively, is the following doing the job?
Starting from the current branch develop
at commit c08e2887
, I was thinking:
new_version
as a backup of the current statedevelop
, git checkout 6a73b96e
to go back to the desired commitdevelop
: now both local and remote branches at commit abc
develop
develop
at commit abc
, create a new branch called old_version
as a backupdevelop
new_version
, create a (now new) branch develop
(this will be equal to what I had before all this process)develop
to the remote branch develop
to go back to what I had before also remotelynew_version
Your suggestion will get the job done, but involves quite a lot of unnecessary steps. Here's a shorter version:
git checkout -b quickfix 6a73b96e # create a new branch from your old commit
# make changes
git commit -m 'these are my changes for commit abc'
git push origin +quickfix:develop # force-push quickfix over develop
# run whatever things you need to run in your remote repository
git push origin +develop:develop # force-push to restore your original develop
Theoretically, you don't even need to create a quickfix
branch and you could simply work in "detached HEAD" state, but it doesn't really matter since the number of commands remains the same.