gpt4 book ai didi

git rebase 导致特性分支丢失跟踪信息

转载 作者:太空狗 更新时间:2023-10-29 13:49:38 28 4
gpt4 key购买 nike

每当我从我们的“主”分支在我的功能分支中 rebase 时,我的功能分支似乎丢失了它的跟踪信息。这个工作流程有什么问题?

$ 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 的变化的功能分支的最佳方法是什么?

最佳答案

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

Rebase 会“重播”您在 master 分支上的所有更改 (git rebase master)。这会重写您的索引。因此,即使您的本地更改全部保留并通过 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 merge master

关于git rebase 导致特性分支丢失跟踪信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17307058/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com