git pull和解决冲突 [英] git pull and resolve conflicts

查看:76
本文介绍了git pull和解决冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习git,并且有一个场景:

I am learning git and I have a scenario:

  1. 我的同事进行更改并将更改推送给主管理员.
  2. 我在本地对我的主人进行更改.

到目前为止,据我所知,我仍然可以:

So far from my understanding, at this point I can either:

  1. 拉扯我同事工作过的母版,并修复最终会遇到的合并冲突.
  2. 创建本地备份,克隆主数据库的新副本,然后将更改合并到主数据库.

我想知道是否还有更好的方法.

I want to know if there is any better way of doing this.

推荐答案

如果远程分支和本地分支上都有不同的更改,而不仅仅是通过

If there are different changes on both the remote and the local branch, instead of just pulling the master by git pull, I rather would do:

git pull --rebase

我什至在我的默认配置中添加了它,以便在git pull上需要时它将始终进行重新设置:

I even have it in my default config so that it will always will do a rebase if required on git pull:

git config --global pull.rebase true

rebase避免了合并提交,并将您的更改保留在当前远程分支的顶部.

A rebase avoids a merge commit and keeps your changes on top of the current remote branch.

但是,当不同的人在同一个分支上工作时,您仍然必须解决所有发生的合并冲突,这是一个不好的做法,尤其是因为这会导致冲突.

Yet you still have to resolve any occurring merge conflicts when different people are working on the same branch, which is a bad practice especially because it leads to conflicts.

(还要注意,在重新定义的范围内,theirsours的含义已切换.)

(Also be aware that in the scope of a rebase, the meaning of theirs and ours is switched.)

在进行较小更改的情况下,您的名称仅显示在顶部.

In cases with minor changes, yours are just applied on the top.

您正在更改历史记录,但仅更改您的本地记录,而不更改远程记录.

You are changing the history, yet only your local one, not the remote's.

不需要需要git push --force.只需按习惯使用git push即可.

You won't need to git push --force. You just git push it as you are used to it.

通常,您应该在要素分支上进行工作,并将其合并回主分支.

In general, you should be working on feature branches and merge those back to the master branch.

在主分支上工作时,还可以通过以下方法使功能分支靠近主分支:

When working on master branches one can also keep the feature branch close to the master by:

git checkout feature-branch
git fetch && git rebase origin/master

但是这里需要git push --force功能分支,因此,如果有多个人在同一个功能分支上工作,则应注意不要使用此策略.

Yet here one would need to git push --force the feature-branch, so one should be careful not to use this strategy if more than one person is working on the same feature-branch.

如果要使用rebase和强制推送,请考虑在git push --force上使用git push --force-with-lease,因为它可以防止意外删除远程服务器上其他用户的提交.

If one wants to use rebase and push forcing, consider using git push --force-with-lease over git push --force as it prevents accidentally deleting other's commits on the remote.

这篇关于git pull和解决冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆