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
552 views
in Technique[技术] by (71.8m points)

git - 如何将Git存储库回滚(重置)到特定的提交? [重复](How do you roll back (reset) a Git repository to a particular commit? [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

I cloned a Git repository and then tried to roll it back to a particular commit early on in the development process.

(我克隆了一个Git存储库,然后尝试在开发过程的早期将其回滚到特定的提交。)

Everything that was added to the repository after that point is unimportant to me so I want to omit all subsequent changes from my local source code.

(在该点之后添加到存储库的所有内容对我来说都不重要,因此我想省略本地源代码中的所有后续更改。)

However, when I try to roll back in the GUI tool it doesn't update my local file system - I always end up with the latest source code for the project.

(但是,当我尝试回滚GUI工具时,它不会更新我的本地文件系统 - 我总是最终得到项目的最新源代码。)

What's the correct way to just get the source for a repository as of a particular commit in the project's history and omit all later updates?

(从项目历史中的特定提交中获取存储库的源代码的正确方法是什么,并省略所有后续更新?)

  ask by translate from so

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

1 Answer

0 votes
by (71.8m points)
git reset --hard <tag/branch/commit id>

Notes:

(笔记:)

  • git reset without the --hard option resets the commit history, but not the files.

    (没有--hard选项的git reset重置提交历史记录,但不会重置文件。)

    With the --hard option the files in working tree are also reset.

    (使用--hard选项,工作树中的文件也会重置。)

    ( credited user )

    (( 贷方用户 ))

  • If you wish to commit that state so that the remote repository also points to the rolled back commit do: git push <reponame> -f ( credited user )

    (如果您希望提交该状态,以便远程存储库也指向回滚提交,请执行以下操作: git push <reponame> -f贷记用户 ))


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

...