Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

git - 回滚到公共回购中的旧Git提交(Rollback to an old Git commit in a public repo)

How can I go about rolling back to a specific commit in git?

(我该如何回滚到git中的特定提交?)

The best answer someone could give me was to use git revert X times until I reach the desired commit.

(有人可以给我的最佳答案是使用git revert X次,直到达到所需的提交。)

So let's say I want to revert back to a commit that's 20 commits old, I'd have to run it 20 times.

(假设我想恢复为20提交的旧提交,我必须运行20次。)

Is there an easier way to do this?

(有没有更简单的方法可以做到这一点?)

I can't use reset because this repository is public.

(我不能使用reset,因为此存储库是公共的。)

  ask by David translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

(尝试这个:)

git checkout [revision] .

where [revision] is the commit hash (for example: 12345678901234567890123456789012345678ab ).

(其中[revision]是提交哈希(例如: 12345678901234567890123456789012345678ab )。)

Don't forget the .

(别忘了.)

at the end, very important.

(最后,非常重要。)

This will apply changes to the whole tree.

(这会将更改应用于整个树。)

You should execute this command in the git project root.

(您应该在git项目根目录中执行此命令。)

If you are in any sub directory, then this command only changes the files in the current directory.

(如果您在任何子目录中,那么此命令仅更改当前目录中的文件。)

Then commit and you should be good.

(然后提交,你应该很好。)

You can undo this by

(您可以通过以下方式撤消该操作)

git reset --hard 

that will delete all modifications from the working directory and staging area.

(它将删除工作目录和登台区域中的所有修改。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...