我在本地机器上创建了一个新的实验分支:
git checkout -b feature/random-experiments
然后对一些文件进行了一些更改并提交了它们:
git add .
git commit -m "1st cut - added cool new experimental feature"
git push
后来,我们创建了一个用户故事(U-123),然后决定重命名我的分支以遵循我们的命名标准。我通过stash的浏览器UI删除了远程分支。然后:
git branch -m feature/U123-Add-Cool-New-Feature
然后做了一些改变并承诺:
git add .
git commit -m "clean up & refactor"
但现在,当我做一个git状态
$ git status
On branch feature/U123-Add-Cool-New-Feature
Your branch and 'origin/feature/random-experiments' have diverged,
and have 1 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
看起来我的本地分支仍然指向旧的远程分支。这是一个问题,因为原始的(远程)分支: 1)有一个不同的名字 2)因为我删除它不再存在。
解决此问题的最佳方法是什么?
答案 0 :(得分:0)
你可以reset the upstream branch for your current branch:
git branch branch_name --set-upstream-to your_new_remote/branch_name
在你的情况下:
git branch --unset-upstream
git push --set-upstream-to origin feature/U123-Add-Cool-New-Feature
确保您在当地的正确分支机构:
git checkout feature/U123-Add-Cool-New-Feature
并试着从那里开始。