If I use T eam F oundation S ource C ontrol I can easily rollback to old changeset.
Assuming I have a file with 4 versions, each version have a changset:
Now I found a lot of bugs in Versions 3 & 4 and I want quickly return back to Version 2.
In Visual Studio I can click "View History" on the file, click on Changeset b347 ("Version 2") and then "Rollback".
Now I have a new changeset with the file in Version 2 and I can check-in it (I still have Version 3/4 in my history, so I can also return to them sometime).
In Git, I know there are revert
, reset
(hard, soft) but I don't know exactly what I need to do to reach the same result.
So what is the best way to rollback to old version in Git (preferred via Visual Studio)?
git reset --hard b347
git push -f origin master
This removes c560
and d912
completely, but after that you need to force-push.
See What's the difference between Git Revert, Checkout and Reset?
To undo changes creating new commits:
git revert d912 c560
Suppose you have 4 commits ABCD
, the file foo.txt
is changed in each of them, and the codes of C
and D
have bugs introduced by foo.txt
.
1.Other files may be changed in C and D. If you want to rollback only foo.txt
to the version of B
:
git checkout B -- foo.txt
If you want to commit the rollback,
git commit
And the history will be ABCD-R1
.
2.If you want to rollback all the changes of C and D (including those of other files if any), and CD have been pushed to the remote repository:
git revert D C
And the history will be ABCD-R2-R3
.
3.If you want to rollback all the changes of C and D, and CD have NOT been pushed to the remote repository:
git reset B --hard
The history will be AB
. You could also use this solution for Case 2, but you then need to force-push the branch to overwrite the branch in the remote repository. If other contributors have fetched the old history, you need to tell them to fetch the new history.
不知道什么是TFVC中的签入,但是如果您只想查看v2文件,则可以git checkout b347 -- thefilenameyouwant
您想要的文件git checkout b347 -- thefilenameyouwant
To continue work on the v2 state of the repository in your working copy, you can do
# get uncommitted changes out of the way
git stash
# recreate v2 in the working copy
git checkout commit-hash-or-tag-of-v2
# create new branch based on v2
git checkout -b branchname-for-new-branch
It's as simple as:
git reset --hard b347
Explanation:
You can simply create a new branch at version 2.
git checkout b347
git checkout -b redo-work-from-version-2
Explanation:
redo-work-from-version-2
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.