对git分支有良好和清晰的理解有分歧的问题? [英] Good and clear understanding of the git branches diverged issue?
问题描述
我搜索了很多帖子,但没有人能让我明白分支分歧问题。
I googled and read many posts, but none could make me understand the branch divergence problem yet.
如果我有远程追踪分支,我经常会遇到以下情况:
If I've remote tracking branch, I often get into the following:
$ git status
# On branch feature/worker-interface
# Your branch and 'origin/feature/worker-interface' have diverged,
# and have 1 and 4 different commit(s) each, respectively.
任何人都可以有任何好的和明确的建议,或者指出有关这个git问题的好消息吗?
Can anyone have any good and clear advice or point into good post about this git issue?
推荐答案
首先,您可以使用 cherry 命令查看分支之间哪些提交不同,以及以何种方式。因此,在这种情况下,运行 git cherry origin / feature / worker-interface
会显示当前分支上的提交状态,以及它们如何与起源/特征/工人接口
。
您会发现1个您忘记提交的回购。
First, you can use the cherry command to see what commits differ between branches, and in what ways. So in this case, running git cherry origin/feature/worker-interface
shows us the status of commits on the current branch and how they stack up against origin/feature/worker-interface
.
You will find 1 repo which you forgot to commit.
现在,让我们看看'origin / feature / worker-interface'和它的提交发生了什么。为此,我们可以运行 log 命令,其格式为 git log .origin / feature / worker-interface --oneline
Now, lets see whats happening with the 'origin/feature/worker-interface' and its commits.For this we can run a log command with a special format git log ..origin/feature/worker-interface --oneline
这里我们看到4个提交不会在我们当前分支中退出
Here we see 4 commits that don't exit in our current branch
所以现在我们有一个好主意,发生了。你已经在你的本地主分支上做了1次提交,看起来你还没有合并到 origin / feature / worker-interface
上4次提交。所以,你可以盲目地将事情合并在一起并继续前进(如果它们没有冲突地合并),但是我想告诉你
如何以更受控制的方式处理它。
So now we have a good idea of what’s happened. you’ve made 1 commits on your local master branch, and it looks like there are 4 commits on origin/feature/worker-interface
which you don’t have merged in yet. So, you could just blindly merge things together and go on your way (if they merge without conflict), but I’d like to show you
how to deal with it in a more controlled manner.
- 首先,创建一个指向当前HEAD的分支:
git checkout -b local_changes
- 现在我们已经掌握了这些变化,我们切换回feature / worker-interface:
git checkout feature / worker-interface
- 此时,重置特性/工作接口分支以摆脱1提交。
- 你走了!您可以检查分支
git status
的状态,您将被提示为无法提交
- First, create a branch that points to your current HEAD:
git checkout -b local_changes
- Now that we have that to keep track of those changes, we switch back to feature/worker-interface:
git checkout feature/worker-interface
- At this point, reset the feature/worker-interface branch to get rid of the 1 commit.
- There you go! You can check your status of branch
git status
you will be prompted as nothing to commit
这篇关于对git分支有良好和清晰的理解有分歧的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!