4

每当我从我们的“主”分支重新定位到我的特性分支时,我的特性分支似乎丢失了它的跟踪信息。这个工作流程有什么问题?

$ git clone repo_url
$ git co -b feature/my_work_task

在这里做一堆工作

$ git commit -am"Commit my work"
$ git push # push the branch upstream
$ git checkout master
$ git pull # get whatever changes that have been put into master
$ git co feature/my_work_task
$ git rebase master # everything seems to be good

在我的功能分支中进行一些额外的更改。

$ git commit -am"more changes to update"
$ git push # pushing this to my remote repo

推送到远程仓库失败并出现以下错误:

To git@github.com:/username/my-repo.git
 ! [rejected]        HEAD -> feature/my_work_task (non-fast-forward)
error: failed to push some refs to 'git@github.com:/username/my-repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我将按照建议执行“git pull”,然后导致:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream feature/my_work_task origin/<branch>

如果我设置上游信息,然后再次尝试“git pull”,我现在将遇到各种文件冲突。

拥有跟上 master 更改的功能分支的最佳方式是什么?

4

1 回答 1

9

推送分支后,您无法对其进行变基。

git rebase masterRebase 在主分支 ( )上“重播”所有更改。这会重写您的索引。因此,即使您的本地更改都被保留并在 master 上重播(所有各种提交,无论您重新设置了多少次),只要您推送远程服务器就会看到不同的索引,从而看到您的错误。

所以,一旦你推送你的分支,你就不能 rebase master。

反而:

  • git checkout -b b
  • git commit -am "stuff"
  • git push origin b
  • git checkout master
  • git pull origin master
  • git checkout b
  • git 合并 master
于 2013-06-25T20:42:22.917 回答