A few important points:
- Commits in git are immutable
- Commits point to zero or more "parents", and history is always examined by following these backwards
- Branches are just a pointer to a particular commit, and from there other commits can be reached
- Branches can be freely moved to point to any commit you want
So, your history looks something like this (the backwards arrows represent the "parents" recorded in each commit):
A <--B <--C <--D
^
|
(develop)
And you want it to look like this:
A <--B <--C <--D
^ ^
| |
(develop) (feature_branch)
So, firstly, with your altered develop checked out, run git branch feature_branch
, giving this:
A <--B <--C <--D
^
|
(develop, feature_branch)
Then find the actual commit hash of commit C (where develop should be pointing) using git log
, and use git reset --hard the_commit_hash_you_found
to point develop back at that commit. (Important: This will wipe out any uncommitted changes. Commit them or use git stash
before you begin!)
A <--B <--C <--D
^ ^
| |
(develop) (feature_branch)
An important note: If you have pushed the version of develop with the changes to a shared server, or anyone else has based anything on it, there is more to do. But if you've just done this locally and not pushed anywhere, the above is all you need.