本文介绍了如何避免重复消息“由于远程包含您所做的工作而导致更新被拒绝..."?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与另外三个合作者进行项目合作,我的情况是:

I am working in a project with three more collaborators, my case is:

每次我尝试添加一个新的提交并且远程中有一些更改(即使它是我在本地未使用的文件)时,我也会收到以下消息,迫使我与以下对象创建合并默认消息:

Every time I try to add a new commit and there is some change in the remote (even though it is a file that I have not worked in local), I get the following message that forces me to create a merge with following default message:

error: failed to push some refs to 'https://work.git.beanstalkapp.com/app.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

只有在遥控器没有任何更改的情况下,才可以避免这种情况.

This scenario is only avoided if there are no changes in the remote.

这会导致许多提交在提交历史记录中看起来像Merge branch 'master' of https://work.git.beanstalkapp.com/app一样,我想避免这种情况.

This causes many commits that look like Merge branch 'master' of https://work.git.beanstalkapp.com/app in the commit history, and I want to avoid that.

我发现了一个相关的,对于某些使用git push -f origin master的人还是可行的,但是使用--force的人会让我担心.我不想破坏项目.

I found a related question, for some people using git push -f origin master is working but using --force worry me. I do not want to damage the project.

我该如何实现?

推荐答案

您想将本地工作重新部署到远程分支上.您可以通过添加 --rebase 标记为git pull:

You want to perform a rebase of your local work onto the remote branch. You can do this by adding the --rebase flag to git pull:

git pull --rebase origin branch

或者,您可以获取远程服务器,然后显式地重新定位:

Alternatively you can fetch the remote and then rebase explicitely:

git fetch origin
git rebase origin/branch

请注意,这会使您明确在本地进行的所有合并变平.您可能需要添加--preserve-merges/--rebase=preserve来避免这种情况(请阅读手册页以获取详细说明).

Note that this flattens any merges you explicitely did locally. You may need to add --preserve-merges / --rebase=preserve to avoid that (read the man pages for detailed explanation).

还请记住,rebase会重写历史记录!重新完成基准之后,重新基准的提交的提交ID将发生更改.

Also keep in mind that rebase rewrites history! After a rebase is done the commit IDs of the rebased commits will have changes.

这篇关于如何避免重复消息“由于远程包含您所做的工作而导致更新被拒绝..."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 01:41