Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git - 返回到以前的状态,但所有下一次提交也保留在日志中(Go back to some previous state, but keep all next commits in log too)

I have branch with 3 commits:

(我有3次提交的分支:)

A -> B -> C (HEAD, master)

Now, if I need go back to A commit, I can use git checkout A , but this loses B and C commits from log.

(现在,如果需要返回到A提交,则可以使用git checkout A ,但这会从日志中丢失BC提交。)

How can I go back to some log, but keep all next commits in log ?

(如何返回某些日志,但将所有下一次提交保留在日志中?)

  ask by OTAR translate from so

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

1 Reply

0 votes
by (71.8m points)

You can branch from A , and keep the log as is in your current branch:

(您可以从A分支,并将日志保留在当前分支中:)

git checkout -b my_branch A

This will create my_branch branch, with HEAD pointing to A .

(这将创建my_branch分支,其中HEAD指向A)

If you now check the log of the branch you created the commit from, you'll see A , B and C :

(如果现在检查创建提交的分支的日志,您将看到ABC :)

$ git log <original_branch>
C (HEAD)
B
A

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...