简体   繁体   English

将提交从一个分支移动到 GitHub 中的另一个分支?

[英]Move Commits from One Branch to Another Branch in GitHub?

I've got two branches on a repo in GitHub;我在 GitHub 的一个 repo 上有两个分支; one is the default branch master , and the other is called gh-pages .一个是默认分支master ,另一个称为gh-pages I set the default branch to be gh-pages on GitHub.我在 GitHub 上将默认分支设置为gh-pages

I use VS Code Editor to code my project ( coder-in-pink ), so I created a new branch named gh-pages in VS Code, and I committed my saved work in the source control.我使用 VS Code 编辑器对我的项目( coder-in-pink )进行coder-in-pink ,因此我在 VS Code 中创建了一个名为gh-pages的新分支,并将我保存的工作提交到源代码管理中。

I'm not allowed to embed pictures in my posts yet, so here's the little picture of the gh-pages branch I set in VS Code .我还不允许在我的帖子中嵌入图片,所以这是我在 VS Code 中设置的 gh-pages 分支的小图片 (It might not be very helpful, though.) (不过,这可能不是很有帮助。)

But today I found out that it had been committed to the master branch.但是今天发现已经提交到master分支了。 How do I move/transfer it to the gh-pages branch?如何将其移动/转移到gh-pages分支?

Thanks!谢谢!

PS I'm planning to make the website with HTTPS and a custom domain afterwards, which is why I want to use the gh-pages branch. PS 我打算在之后使用 HTTPS 和自定义域制作网站,这就是我想使用gh-pages分支的原因。

Here's the link to my repo on GitHub => Coder In Pink .这是我在 GitHub 上的 repo 的链接 => Coder In Pink

Here's what I would do这就是我要做的

  1. Merge master to gh-pages - this would bring the commit to gh-pages .master合并到gh-pages - 这会将提交带到gh-pages

  2. Revert the commit in master , if needed, by git revert commit-id .如果需要,通过git revert commit-id master git revert commit-id


Update更新

I found this by coincidence.我偶然发现了这个。

The GitHub Blog's How to undo (almost) anything with Git has a section that matches your scenario. GitHub 博客的如何使用 Git 撤消(几乎)任何事情有一个部分与您的场景相匹配。

Once more, with branching再一次,与分支

Scenario : You made some commits, then realized you were checked out on master.场景:您进行了一些提交,然后意识到您已在 master 上签出。 You wish you could make those commits on a feature branch instead.您希望可以在功能分支上进行这些提交。

(...) (……)

git checkout gh-pages This makes sure you're on the gh-pages branch git checkout gh-pages这确保你在gh-pages分支上

git merge master This merges master into gh-pages git merge master这将 master 合并gh-pages

Finally git push origin gh-pages This will push your changes back to GitHub.最后git push origin gh-pages这会将您的更改推送回 GitHub。 Origin isn't needed, but this is the long-form way of doing it.不需要 Origin,但这是这样做的长期方式。

The short way is just git push while being checked out on gh-pages简短的方法是在gh-pages上签出时git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM