Case:
The commit history is:
A -> B -> C -> D
I hope to reset the current work dir to B on current branch with history:
A -> B -> C -> D -> E
The result of the tree is same to B
, which means
git diff B..E --name-only
should returns empty list.
A stupid way is:
# we assume current work directory is `tree`, and branch is `master`
# and work directory HEAD at `D`
# reset HEAD to D
cd tree
git checkout -f D
# create a copy work directory
cd ..
rm -rf copy
cp -r tree copy
# clean old work directory
rm -rf tree
mkdir tree
cp -r copy/.git tree/.git
# reset copy directory to revision `B`
cd copy
git checkout -f B
# copy tree from copy directory to tree
rm -rf .git
cp -r ./.* ./* ../tree
# commit changes, current revision is we wanted `E`
git add .
git ci -m 'revert to commit B'
Is there a simplified way to do this?