每当我在我的'master'分支的功能分支中进行变基础时,我的功能分支似乎丢失了它的跟踪信息。这个工作流程出了什么问题?
$ 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',我现在会遇到各种各样的文件冲突。
有哪个功能分支可以跟上主变化的最佳方法是什么?
答案 0 :(得分:9)
推动分支后,您无法对其进行修改。
Rebase'重放'对主分支(git rebase master
)的所有更改。这会重写您的索引。因此,即使您的本地更改都保留并通过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