在 GitHub 中将提交从一个分支移动到另一个分支?
Move Commits from One Branch to Another Branch in GitHub?
我在 GitHub 的 repo 上有两个分支;一个是默认分支 master
,另一个称为 gh-pages
。我在 GitHub.
上将默认分支设置为 gh-pages
我使用 VS Code 编辑器对我的项目 (coder-in-pink
) 进行编码,因此我在 VS Code 中创建了一个名为 gh-pages
的新分支,并将保存的工作提交到源代码管理中。
我还不允许在我的帖子中嵌入图片,所以这里是 the little picture of the gh-pages branch I set in VS Code。 (不过,这可能不是很有帮助。)
但是今天发现已经提交到master
分支了。我如何 move/transfer 它到 gh-pages
分支?
谢谢!
P.S。我计划之后使用 HTTPS 和自定义域制作网站,这就是为什么我想使用 gh-pages
分支。
这是我在 GitHub 上的回购 link => Coder In Pink。
这是我会做的
合并 master
到 gh-pages
- 这会将提交带到 gh-pages
。
如果需要,由 git revert commit-id
恢复 master
中的提交。
更新
偶然发现的
GitHub 博客的 How to undo (almost) anything with Git 有一个部分符合您的情况。
Once more, with branching
Scenario: You made some commits, then realized you were checked out on master. You wish you could make those commits on a feature branch instead.
(...)
git checkout gh-pages
这确保您在 gh-pages
分支
git merge master
这会将 master 合并到 gh-pages
终于
git push origin gh-pages
这会将您的更改推回到 GitHub。不需要 Origin,但这是执行此操作的长格式。
在 gh-pages
签出时,最短的方法就是 git push
我在 GitHub 的 repo 上有两个分支;一个是默认分支 master
,另一个称为 gh-pages
。我在 GitHub.
gh-pages
我使用 VS Code 编辑器对我的项目 (coder-in-pink
) 进行编码,因此我在 VS Code 中创建了一个名为 gh-pages
的新分支,并将保存的工作提交到源代码管理中。
我还不允许在我的帖子中嵌入图片,所以这里是 the little picture of the gh-pages branch I set in VS Code。 (不过,这可能不是很有帮助。)
但是今天发现已经提交到master
分支了。我如何 move/transfer 它到 gh-pages
分支?
谢谢!
P.S。我计划之后使用 HTTPS 和自定义域制作网站,这就是为什么我想使用 gh-pages
分支。
这是我在 GitHub 上的回购 link => Coder In Pink。
这是我会做的
合并
master
到gh-pages
- 这会将提交带到gh-pages
。如果需要,由
git revert commit-id
恢复master
中的提交。
更新
偶然发现的
GitHub 博客的 How to undo (almost) anything with Git 有一个部分符合您的情况。
Once more, with branching
Scenario: You made some commits, then realized you were checked out on master. You wish you could make those commits on a feature branch instead.
(...)
git checkout gh-pages
这确保您在 gh-pages
分支
git merge master
这会将 master 合并到 gh-pages
终于
git push origin gh-pages
这会将您的更改推回到 GitHub。不需要 Origin,但这是执行此操作的长格式。
在 gh-pages
git push