0

当我在我的项目中的 D 点时,我对我的项目进行了一些更改并将几个提交(E,F,G,H)推送到 git,所以我在 H 点。
现在我必须做出新的更改(I)并将它们推送到 git 并部署,但我不希望部署我的旧提交(E、F、G、H)。
我想回到 D 进行更改(I)并在不丢失旧提交(E、F、G、H)的情况下部署它,然后从 H 点继续处理我的项目。我只有一个分支 MASTER

我知道我可以做一个 git checkout H 回到 H 点。
我知道因为已经提交了更改(E,F,G,H)......

IE

A - B - C - D - E - F - G - H
             \             /
              I ----------      

可能吗?

4

2 回答 2

3
git checkout [sha for d] -b [branch name]
[make your changes]
[git add your changes]
[git commit]
[push branch]
[deploy the branch]
git checkout - # checks out back to the last checkout ref
于 2013-10-16T22:28:04.787 回答
1

假设所有提交 A 到 H 存在并且您在点 H(即 master 的 HEAD,因为您声明您只有一个分支),您可以尝试:

git reset --hard HEAD~4           // Rolls you back to working state of D
git checkout -b branch_for_i      // Digress work from D on a new branch

** Make necessary changes for I

git commit                        // Commits changes required for I
git push origin branch_for_i      // Pushes up changes done for I
git checkout master               // Back to the branch with H as HEAD
git reset --hard HEAD             // Puts you back into the working state at H
于 2013-10-17T08:11:42.357 回答