Reputation: 8190
I need to remove my last two commits but also need to save some data from these commits (one folder). And merge that into my 3rd commit. How can i do that ?
Upvotes: 1
Views: 62
Reputation: 40061
You can reset back to two-commits ago using
git reset --mixed HEAD~2
This will reset the branch but keep all the changes those two commits. Then simply add and commit what you need to save
git add <important folder>
git commit -m'added important folder'
Upvotes: 2
Reputation: 7865
git rebase -i HEAD~2
allows you to edit previous 3 commits.
You probably want to apply the squash command on the interactive shell
Upvotes: 0
Reputation: 36472
Simply stop thinking about it in the terms of "removing commits". I'd say:
Note down the current commit ID:
git log |head -n1
go back two commits,
git checkout HEAD~2
then check out only your directory
git checkout <noted ID> -- yourdirectory/
and commit the result:
git commit -m "kept the future of yourdirectory/" yourdirectory
And if you really want to meddle with an existing commit, use
git rebase -i HEAD~10
to squash these two commits.
If you really want to (you don't have to) you can git prune
the dangling commits later on.
Upvotes: 2