gpt4 book ai didi

git branching - 如何使当前 master 成为一个分支,然后将 master 恢复到以前的版本?

转载 作者:太空狗 更新时间:2023-10-29 13:31:04 25 4
gpt4 key购买 nike

这可能很简单,但我目前是一个 git 菜鸟,还没有完全了解 git 分支模型。

假设我目前除了master 没有分支,但自上次提交以来我已经做了一些我决定不想保留的更改(注意:更改尚未提交)。不过,我还不想摆脱这些更改——我想将它们放在它们自己的分支中(例如称为 experimental_stuff ),然后从我之前的提交继续开发。所以我想步骤是:

  • 让当前的master成为一个分支(git branch experimental_stuff?)
  • 回到之前的提交(git checkout <last_commit>?)
  • 将其作为我的新主分支,以便 future 的提交从这里继续(git ????)

这是正确的方法吗?最后一部分(如果有的话)我需要什么 git 命令?

[注意:这只是一个供我单独使用的本地 git 存储库,如果有任何不同的话。]

最佳答案

你快完成了。

假设您已经提交了您的开发文件。然后..

git branch experimental_stuff

git reset --hard HEAD^ (go back one previous commit of your master branch to continue your development)

假设您还没有提交您的开发文件。然后..您需要将当前更改保存到临时目录

git stash

git checkout -b experimental_stuff (create and change branch to experiental_stuff)

git stash pop (populate the temporary directory into experimental branch)

git checkout master (return back to master, and no need to go back the previous commit this time as you don't have that commit)

关于git branching - 如何使当前 master 成为一个分支,然后将 master 恢复到以前的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6764893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com