如何解决分支和 orgin/branch 已经分歧?
How do I resolve a branch and orgin/branch that have diverged?
通过重置为较早的提交,我无法按顺序恢复本地分支。我一直在本地遇到合并冲突,而远程版本没有任何冲突,我想要的是在我的本地分支中获取 fremote 的精确副本。
我能做的是 git checkout <last commit>
,我基本上会在我的本地目录中获取遥控器的副本,但随后我还会得到:
$ git checkout bd8b876
Note: checking out 'bd8b876'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
我不想要,因为我仍然需要在这个分支上工作。
我不想开始一个新分支,因为分支名称与链接到 JIRA 票证的脚本相关联。如果没有别的办法,我也会这样做。
我尝试解决的问题:
git reset --hard HEAD
现在在 8dc6510 更新 main.py
git status
On branch OS-4055-header_bar_Drive_parameters
Your branch and 'origin/branch' have diverged,
and have 19 and 3 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
但这会使我的本地文件始终处于合并状态。我认为 pull
是 fetch
和 merge
的组合。
我也试过(重置后):$ git fetch origin branch:branch
但即使那样也不会给我预期的结果。我检查了另一个系统上的分支,文件按预期进入(w/o 合并冲突)。如何在不需要完全删除我的源目录的情况下让我的本地分支工作副本进入该状态?
`
I keep getting merge conflicts locally, while the version on remote
does not have any conflicts and what I want, is to get an exact copy
of the fremote in my local branch.
因此,您想将遥控器中的任何内容都保留为 "good" 内容。只需执行一个新的克隆并删除您当前的工作目录。
How do I get my local branch working copy into that state without the
need to entirely delete my source directory?
因此您不想这样做,但无论哪种方式,您都必须删除发生分歧的本地提交,因为它们发生分歧并且您想保留远程中的任何内容。
git commit --amend
所有发散的本地提交,甚至 git reset --hard
直到您有效删除所有本地提交。您可以通过多种方式实现 "commits" 的删除。执行此操作,直到您到达本地和远程共享的最后一个共同提交。
一旦你在这里,如果任何文件被修改,然后 git stash
它或 git checkout --
它恢复到 HEAD 原始状态。
现在,git pull
将获取并合并远程中您迫切需要的所有内容。
重新应用您隐藏的任何想要的更改,创建一个新的提交并将其推送到远程。重复直到 Jira 问题关闭 ;)
顺便说一句:我仍然不相信您的本地和远程历史有何不同。我希望你把自己放在那种情况下,没有人会在没有合并策略的情况下推到你的同一个分支......
通过重置为较早的提交,我无法按顺序恢复本地分支。我一直在本地遇到合并冲突,而远程版本没有任何冲突,我想要的是在我的本地分支中获取 fremote 的精确副本。
我能做的是 git checkout <last commit>
,我基本上会在我的本地目录中获取遥控器的副本,但随后我还会得到:
$ git checkout bd8b876
Note: checking out 'bd8b876'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
我不想要,因为我仍然需要在这个分支上工作。
我不想开始一个新分支,因为分支名称与链接到 JIRA 票证的脚本相关联。如果没有别的办法,我也会这样做。
我尝试解决的问题:
git reset --hard HEAD
现在在 8dc6510 更新 main.py
git status
On branch OS-4055-header_bar_Drive_parameters
Your branch and 'origin/branch' have diverged,
and have 19 and 3 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
但这会使我的本地文件始终处于合并状态。我认为 pull
是 fetch
和 merge
的组合。
我也试过(重置后):$ git fetch origin branch:branch
但即使那样也不会给我预期的结果。我检查了另一个系统上的分支,文件按预期进入(w/o 合并冲突)。如何在不需要完全删除我的源目录的情况下让我的本地分支工作副本进入该状态?
`
I keep getting merge conflicts locally, while the version on remote does not have any conflicts and what I want, is to get an exact copy of the
fremote in my local branch.
因此,您想将遥控器中的任何内容都保留为 "good" 内容。只需执行一个新的克隆并删除您当前的工作目录。
How do I get my local branch working copy into that state without the need to entirely delete my source directory?
因此您不想这样做,但无论哪种方式,您都必须删除发生分歧的本地提交,因为它们发生分歧并且您想保留远程中的任何内容。
git commit --amend
所有发散的本地提交,甚至 git reset --hard
直到您有效删除所有本地提交。您可以通过多种方式实现 "commits" 的删除。执行此操作,直到您到达本地和远程共享的最后一个共同提交。
一旦你在这里,如果任何文件被修改,然后 git stash
它或 git checkout --
它恢复到 HEAD 原始状态。
现在,git pull
将获取并合并远程中您迫切需要的所有内容。
重新应用您隐藏的任何想要的更改,创建一个新的提交并将其推送到远程。重复直到 Jira 问题关闭 ;)
顺便说一句:我仍然不相信您的本地和远程历史有何不同。我希望你把自己放在那种情况下,没有人会在没有合并策略的情况下推到你的同一个分支......