Reputation: 141
Hey I am new to github so please help me out.
I have four commits.
commit4 eh87eg87
commit3 e3e983jj
commit2 de6d6e3d
commit1 du3qw6y1
I want to go back to commit2 and make changes to it and commit it (commit 5) and not lose the rest of the commits like commit4, commit3, commit2 and commit1.
Upvotes: 1
Views: 50
Reputation: 1
you might try to
git revert --no-commit de6d6e3d
... hack ...
git commit -m "re commit2"
if you found the best solution, you might want to add it here: https://git.wiki.kernel.org/index.php/GitSvnClient_(git-svn)
Upvotes: 0
Reputation: 11601
You can try two things:
git rebase --interactive <ID of the commit before commit1>
. Read the documentation that git prints for you. Basically, you have to use edit
instead of pick
for commit1
, amend
your commit, then continue the rebase.git reset --hard <ID of the commit before commit1>
, then take each commit in order and copy them using git cherry-pick <ID of commit>
, change the files that you want to change then git commit --ammend
, and go to the next one.Upvotes: 1
Reputation: 51945
You can just create another branch, which will serve as an identifier for your "dangling" commits, and then reset your current branch to commit 2:
git branch temp_branch
(you can choose any name here)git reset --hard de6d6e3d
(the SHA of commit 2)After creating the temporary branch in step 1, you will still be on your original branch. Once you reset that, you can continue working upon commit 2, and if you need the other two commits, just checkout temp_branch (or use it for rebase, cherry-pick, etc.)
Upvotes: 0