git 将本地提交的更改移动到新分支并推送

标签 git branch git-branch rebase git-rebase

我在 master 上。当我执行 git status 时,我被告知

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 13 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

所以所有 13 个都只存在于我的本地机器上。问题是这 13 次提交现在应该在我应该创建并推送到服务器上的新分支上进行。我曾尝试查看 rebase ,但有人告诉我

$ git rebase origina/master
fatal: Needed a single revision
invalid upstream origina/master

我怎样才能将这些更改推送到一个新分支而不弄乱 master?

只是为了澄清。这不是
的副本 moving committed (but not pushed) changes to a new branch无论我做什么,这个都对我不起作用。
或者
Git: Howto move changes since last commit to a new branch再次没有帮助。

最佳答案

只需执行 git checkout -b yourbranch 并推送即可。

然后将master重置为origin/master。

顺序:

git checkout -b mybranch
git push
git checkout master
git reset --hard origin/master

关于git 将本地提交的更改移动到新分支并推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429091/

相关文章:

git - 我可以在不先提交的情况下推送我的工作目录吗?

git - 撤消 git commit amend 并保留索引中的更改

python - 从提交中获取 GitHub 存储库 URL

git - 在 git 上 merge 一个主题分支,删除所有主题分支的提交历史?

Git 和分支

git - 为什么 git fetch 不创建本地分支?

Git refs - 为什么它被称为头而不是分支?

git - Git 的提交日期或作者日期时间戳的分辨率是多少?

git - 我们真的需要在 Git 中分支吗?

git - 为什么我不能推送我的新分支?