git修改后git合并冲突 - "你的分支和'origin/master'分歧了"

Ami*_*ole 9 git git-amend merge-conflict-resolution

这是发生的事情:

  1. 在最近提交给远程主人之后,我对我的本地仓库做了一个小小的改变
  2. 我添加git commit --amend并保留与HEAD相同的提交消息
  3. 我试着将回购推广给主人 git push

现在我明白了

On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)

我想明白:

  1. 为什么会这样?
  2. 我该怎么做才能防止这种情况发生?
  3. git修改后如何调和master和local?

Von*_*onC 10

您更改了现有的推送提交,创建了自己的版本(因为其内容已更改)

 --x---Y (master: that is the X amended)
    \
     --X (origin/master)
Run Code Online (Sandbox Code Playgroud)

这就是为什么你在master和origin/master之间有1个和1个不同的提交

我该怎么做才能防止这种情况发生?

不要"修改"现有的推送提交(只有本地尚未推送的提交)

git修改后如何调和master和local?

只需在原点/主控上重新设置,然后按下

git rebase origin/master

 --x--X---Y' (master)
      |
(origin/master)

git push

 --x--X---Y' (master, origin/master)
Run Code Online (Sandbox Code Playgroud)