Reputation: 40639
I want to keep the index exactly as it is right now, but I want to directly load a specific commit into the worktree. Is there a way to do this in git?
Upvotes: 2
Views: 106
Reputation: 19475
Although the previous answer has been accepted, I don't think it really
answers the question. It would not leave the index in the initial state,
instead it resets the index to match HEAD after updating the working tree.
This would lose any work that had been done with git add
.
Instead, I'd use a temporary index:
export GIT_INDEX_FILE=.git/tmpindex
git read-tree abc123 # Read commit into (temporary) index file
git checkout . # Update working tree with contents of (temporary) index
rm $GIT_INDEX_FILE
unset GIT_INDEX_FILE
This would truly leave the normal index in the original state.
Upvotes: 4
Reputation: 46667
It looks like you can't do it in one command, but you should be able to with two:
$> git cherry-pick -n abc123 # cherry-pick to index and WC, no commit
$> git reset # revert index
Upvotes: 1