如何在正确的分支中转移提交?我把它推到 master 而不是正确的功能分支

How to shif a commit in the correct branch? I pushed it into the master instead into the correct feature branch

我不太喜欢 GIT,我遇到了以下问题。

我在 BitBucket 上创建了一个新的存储库,并创建了一个名为 feature/skeleton.

的新功能分支

然后我犯了以下错误:我推错了分支(我把我的代码推到了 master 分支),正如你在这里看到的:

我该怎么做才能将此提交(具有 ID=b3542a8)转移(或类似这样)到正确的 feature/skeleton 分支?

当您创建 feature/skeleton 分支时,您可能遗漏了 --no-track 标志,因此您的分支指向 origin/master。从概念上讲,您可以这样做:

  1. 将您的本地分支指向正确的上游分支(可能 origin/feature/skeleton),然后重新推送它。
  2. 更改 origin/master 以返回到之前的状态。

实现此目的的命令是(假设您的遥控器是 origin):

# Get your local repo copy up to date
git fetch
# checkout your feature branch
git checkout feature/skeleton
# set the proper upstream
git branch --set-upstream-to=origin/feature/skeleton
# push out your branch to the proper remote branch
git push

# now we'll fix master by checking it out
git checkout master
# set master to the commit ID you want it to be on (maybe it's c6afa8f), if needed
git reset --hard c6afa8f
# replace the remote master
git push --force-with-lease

就是这样!