标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:How to revert a Git repository to a previous commit41 answersWith git log, I get a list of commits that I have made so far. commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1Author: prosseek Date: Fri Sep 3 14:36:59 2010 -0500Added and modified the files.commit c14809fafb08b9e96ff2879999ba8c807d10fb07Author: prosseek Date: Tue Aug 31 08:59:32 2010 -0500Just simple test for core.editor.... etc ...How can I revert it back to a specific commit? For example, what should I do if I want to go back to commit c14809fafb08b9e96ff2879999ba8c807d10fb07?Is there any other/better way to go back to a specific commit with Git? For example, can I put some label of each commit to get it back with the label?


Even though this question is actually older than the one it's now marked as a duplicate of, that one has a better answer. meta.stackexchange.com/questions/147643/…

2019年05月22日50分22秒

This is a perfect example of how f--k'd up git is (from bwawok's answer): "... then if you wanted to push this to someone else who has the new history, it would fail". What good is it if you can't check it back into the remote repository??? I am absolutely amazed at how difficult Git has made simple operations.

2019年05月22日50分22秒

jww I literally have been reading for an hour now on how to go back to a previous commit and I still don't know the answer. You are absolutely correct, git makes things more complicated than it should be.

2019年05月22日50分22秒

I needed to roll back to that state. But it's good to know that I may have the option of 'look like that'.Thanks for letting me know. BTW, what option is the default? hard or soft?

2019年05月22日50分22秒

prosseek the default is actually mixed.--mixed Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.See kernel.org/pub/software/scm/git/docs/git-reset.html

2019年05月22日50分22秒

Peter's answer below makes more sense than this

2019年05月22日50分22秒

To clarify: "git reset --soft" does NOT leave the history the same, as it removes all the commit entries done after the one reset to and labels the files from those newer commits as "Changes to be committed". I guess it depends on how you define "history". The sentence "but leave your history etc. the same." made me interpret this answer as if the command doesn't affect any of the commits at all, which it does. See Peter A's answer on how to keep the commits done after the commit reverted to.

2019年05月22日50分22秒

I come to this same place whenever I'm in trouble. Thank you!! :D

2019年05月22日50分22秒

a great guy with as yet, a low reputation :)

2019年05月22日50分22秒

but git checkout is read only, therefore you can't commit an old revision.

2019年05月22日50分22秒

Peter A: After "git reset --soft" followed by "git checkout", I don't see a change to a file I've been working on. Could it be because I'm not in the master branch?

2019年05月22日50分22秒

Also you can then do 'git checkout <YOUR_BRANCH>' to come to the original state after viewing different commits.

2019年05月22日50分22秒

Won't have to type the entire sha, just a little bit will work

2019年05月22日50分22秒

bwawok: But it's faster to select and middle-click-paste than to type even an abbreviated SHA1!

2019年05月22日50分22秒

Will a git push origin mybranch then cause the origin repo to be reverted?

2019年05月22日50分22秒

in what cases would you need to force?

2019年05月22日50分22秒

what does "at the time of the checkin" mean? ambiguous.if I do "git reset --hard X" is the repo state same as before commit X or after commit X ...

2019年05月22日50分22秒

git reset --hard X. This will roll back the repository state as before commit X. It will make your local code and local history be just like it was at that commit. But then if you wanted to push this to local master or remote master with different history, it would fail. So it will be read only version of your repository.

2019年05月22日50分22秒