为什么 git 警告我我的分支已与 master 分支分歧?
我正在为 LibreOffice 做出贡献,并已开始学习 git。我已经克隆了 LibreOffice 存储库并成功构建。 LibreOffice 有 19 个 git 存储库,其中 1 个被命名为 bootstrap,并保持在较低的一层,被命名为 writer、calc、postprocess、base 等。它有一个名为 g
的脚本,用于在所有存储库中同时运行 git 命令而不是单独运行。
克隆后,我创建了一个补丁,并将其推送到远程存储库中。此时我的所有更改都已提交(即 git diff 不输出任何内容),状态是我在 master 分支之前提交。
现在,当我运行 ./g pull -r
时,我得到以下输出:
victor@victor-laptop:~/git/libo$ ./g pull -r
===== main repo =====
Current branch master is up to date.
===== artwork =====
Current branch master is up to date.
===== base =====
Current branch master is up to date.
===== calc =====
Current branch master is up to date.
===== components =====
Current branch master is up to date.
===== extensions =====
Current branch master is up to date.
===== extras =====
Current branch master is up to date.
===== filters =====
Current branch master is up to date.
===== help =====
Current branch master is up to date.
===== impress =====
Current branch master is up to date.
===== libs-core =====
Current branch master is up to date.
===== libs-extern =====
Current branch master is up to date.
===== libs-extern-sys =====
Current branch master is up to date.
===== libs-gui =====
From http://anongit.freedesktop.org/git/libreoffice/libs-gui
08137a2..d314277 master -> origin/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to d3142771895c2e9ce029e3b52af7f1ea1b437a6b.
===== postprocess =====
Current branch master is up to date.
===== sdk =====
Current branch master is up to date.
===== testing =====
Current branch master is up to date.
===== ure =====
Current branch master is up to date.
===== writer =====
U sw/source/core/doc/docdesc.cxx
U sw/source/core/frmedt/fews.cxx
M sw/source/core/inc/SwXMLBlockExport.hxx
U sw/source/core/inc/UndoCore.hxx
U sw/source/core/inc/ascharanchoredobjectposition.hxx
U sw/source/core/inc/frame.hxx
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
这显示了写入模块(sw)中某些文件的一些问题,并且提到的文件是补丁中使用的文件中的一些文件我贡献了。
git diff
显示了这一点:
victor@victor-laptop:~/git/libo$ cd sw
victor@victor-laptop:~/git/libo/sw$ git diff
diff --cc sw/source/core/doc/docdesc.cxx
index 0900b18,52b984e..0000000
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@@ -216,7 -216,7 +216,11 @@@ void SwDoc::ChgPageDesc( sal_uInt16 i,
if( rChged.GetNumType().GetNumberingType() != pDesc->GetNumType().GetNumbe
{
pDesc->SetNumType( rChged.GetNumType() );
++<<<<<<< HEAD
+ // den Seitennummernfeldern bescheid sagen,
++=======
+ // Bug 64121 - den Seitennummernfeldern bescheid sagen,
++>>>>>>> Removal of bogus comments in writer module
// das sich das Num-Format geaendert hat
GetSysFldType( RES_PAGENUMBERFLD )->UpdateFlds();
GetSysFldType( RES_REFPAGEGETFLD )->UpdateFlds();
diff --cc sw/source/core/frmedt/fews.cxx
index 6fe4bf0,4dc82ff..0000000
--- a/sw/source/core/frmedt/fews.cxx
+++ b/sw/source/core/frmedt/fews.cxx
@@@ -1266,6 -1267,7 +1266,10 @@@ Size SwFEShell::GetGraphicDefaultSize(
return aRet;
}
++<<<<<<< HEAD
++=======
+ // add output parameter <bVertL2R>
++>>>>>>> Removal of bogus comments in writer module
sal_Bool SwFEShell::IsFrmVertical(const sal_Bool bEnvironment, sal_Bool& bRTL,
{
sal_Bool bVert = sal_False;
diff --cc sw/source/core/inc/UndoCore.hxx
index e8fda05,99f4722..0000000
--- a/sw/source/core/inc/UndoCore.hxx
+++ b/sw/source/core/inc/UndoCore.hxx
@@@ -133,6 -133,7 +133,10 @@@ class SwUndoFmtColl : public SwUndo, pr
void DoSetFmtColl(SwDoc & rDoc, SwPaM & rPaM);
public:
++<<<<<<< HEAD
++=======
+ // SwUndoFmtColl( const SwPaM&, SwFmtColl* );
++>>>>>>> Removal of bogus comments in writer module
SwUndoFmtColl( const SwPaM&, SwFmtColl*,
const bool bReset,
const bool bResetListAttrs );
@@@ -202,6 -203,7 +206,10 @@@ public
virtual void RepeatImpl( ::sw::RepeatContext & );
};
++<<<<<<< HEAD
++=======
+ //--------------------------------------------------------------------
++>>>>>>> Removal of bogus comments in writer module
const int nUndoStringLength = 20;
diff --cc sw/source/core/inc/ascharanchoredobjectposition.hxx
index 16dde41,2f868a9..0000000
--- a/sw/source/core/inc/ascharanchoredobjectposition.hxx
+++ b/sw/source/core/inc/ascharanchoredobjectposition.hxx
@@@ -140,7 -140,7 +140,11 @@@ namespace objectpositionin
Point GetAnchorPos() const;
// calculated relative position to base line for object position ty
++<<<<<<< HEAD
+
++=======
+
++>>>>>>> Removal of bogus comments in writer module
SwTwips GetRelPosY() const;
// determined object rectangle including spacing for object position
diff --cc sw/source/core/inc/frame.hxx
index 664f28b,94db9cc..0000000
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@@ -248,6 -250,9 +248,12 @@@ enum MakePageTyp
MAKEPAGE_NOSECTION // Don't create section frames
};
++<<<<<<< HEAD
++=======
+ // #i28701# - replaced by new class <SwSortedObjs>
+ //typedef SdrObject* SdrObjectPtr;
+ //SV_DECL_PTRARR(SwDrawObjs,SdrObjectPtr,1,1);
++>>>>>>> Removal of bogus comments in writer module
class SwFrm: public SwClient, public SfxBroadcaster
{
(END)
并且 git status
显示了这一点:
victor@victor-laptop:~/git/libo/clone/writer$ git status
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: sw/source/core/inc/SwXMLBlockExport.hxx
#
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: sw/source/core/doc/docdesc.cxx
# both modified: sw/source/core/frmedt/fews.cxx
# both modified: sw/source/core/inc/UndoCore.hxx
# both modified: sw/source/core/inc/ascharanchoredobjectposition.hxx
# both modified: sw/source/core/inc/frame.hxx
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# 0001-Removal-of-bogus-comments-in-writer-module.patch
如果我尝试通过手动编辑这些文件来解决冲突,git 会告诉我我的 master 已偏离 origin/master 。这种情况持续循环。请帮帮我。问题是什么?我该如何解决它?
I'm contributing to LibreOffice and have started learning git. I've cloned the LibreOffice repository and got the successful build. LibreOffice has 19 git repositories 1 named as bootstrap and remaining at one level lower named as writer, calc, postprocess, base etc. It has got a script maned g
for running the git commands simultaneously in all the repositories instead of running then individually.
After cloning I created a patch which was pushed in remote repository. At this moment all my changes have been committed(i.e. git diff
outputs nothing) and status is that I'm a commit ahead of master branch.
Now when I run ./g pull -r
i get this output:
victor@victor-laptop:~/git/libo$ ./g pull -r
===== main repo =====
Current branch master is up to date.
===== artwork =====
Current branch master is up to date.
===== base =====
Current branch master is up to date.
===== calc =====
Current branch master is up to date.
===== components =====
Current branch master is up to date.
===== extensions =====
Current branch master is up to date.
===== extras =====
Current branch master is up to date.
===== filters =====
Current branch master is up to date.
===== help =====
Current branch master is up to date.
===== impress =====
Current branch master is up to date.
===== libs-core =====
Current branch master is up to date.
===== libs-extern =====
Current branch master is up to date.
===== libs-extern-sys =====
Current branch master is up to date.
===== libs-gui =====
From http://anongit.freedesktop.org/git/libreoffice/libs-gui
08137a2..d314277 master -> origin/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to d3142771895c2e9ce029e3b52af7f1ea1b437a6b.
===== postprocess =====
Current branch master is up to date.
===== sdk =====
Current branch master is up to date.
===== testing =====
Current branch master is up to date.
===== ure =====
Current branch master is up to date.
===== writer =====
U sw/source/core/doc/docdesc.cxx
U sw/source/core/frmedt/fews.cxx
M sw/source/core/inc/SwXMLBlockExport.hxx
U sw/source/core/inc/UndoCore.hxx
U sw/source/core/inc/ascharanchoredobjectposition.hxx
U sw/source/core/inc/frame.hxx
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
which shows some problem with some files in the write module (sw) and the files mentioned are some from the ones used in the patch which I contributed.
the git diff
shows this:
victor@victor-laptop:~/git/libo$ cd sw
victor@victor-laptop:~/git/libo/sw$ git diff
diff --cc sw/source/core/doc/docdesc.cxx
index 0900b18,52b984e..0000000
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@@ -216,7 -216,7 +216,11 @@@ void SwDoc::ChgPageDesc( sal_uInt16 i,
if( rChged.GetNumType().GetNumberingType() != pDesc->GetNumType().GetNumbe
{
pDesc->SetNumType( rChged.GetNumType() );
++<<<<<<< HEAD
+ // den Seitennummernfeldern bescheid sagen,
++=======
+ // Bug 64121 - den Seitennummernfeldern bescheid sagen,
++>>>>>>> Removal of bogus comments in writer module
// das sich das Num-Format geaendert hat
GetSysFldType( RES_PAGENUMBERFLD )->UpdateFlds();
GetSysFldType( RES_REFPAGEGETFLD )->UpdateFlds();
diff --cc sw/source/core/frmedt/fews.cxx
index 6fe4bf0,4dc82ff..0000000
--- a/sw/source/core/frmedt/fews.cxx
+++ b/sw/source/core/frmedt/fews.cxx
@@@ -1266,6 -1267,7 +1266,10 @@@ Size SwFEShell::GetGraphicDefaultSize(
return aRet;
}
++<<<<<<< HEAD
++=======
+ // add output parameter <bVertL2R>
++>>>>>>> Removal of bogus comments in writer module
sal_Bool SwFEShell::IsFrmVertical(const sal_Bool bEnvironment, sal_Bool& bRTL,
{
sal_Bool bVert = sal_False;
diff --cc sw/source/core/inc/UndoCore.hxx
index e8fda05,99f4722..0000000
--- a/sw/source/core/inc/UndoCore.hxx
+++ b/sw/source/core/inc/UndoCore.hxx
@@@ -133,6 -133,7 +133,10 @@@ class SwUndoFmtColl : public SwUndo, pr
void DoSetFmtColl(SwDoc & rDoc, SwPaM & rPaM);
public:
++<<<<<<< HEAD
++=======
+ // SwUndoFmtColl( const SwPaM&, SwFmtColl* );
++>>>>>>> Removal of bogus comments in writer module
SwUndoFmtColl( const SwPaM&, SwFmtColl*,
const bool bReset,
const bool bResetListAttrs );
@@@ -202,6 -203,7 +206,10 @@@ public
virtual void RepeatImpl( ::sw::RepeatContext & );
};
++<<<<<<< HEAD
++=======
+ //--------------------------------------------------------------------
++>>>>>>> Removal of bogus comments in writer module
const int nUndoStringLength = 20;
diff --cc sw/source/core/inc/ascharanchoredobjectposition.hxx
index 16dde41,2f868a9..0000000
--- a/sw/source/core/inc/ascharanchoredobjectposition.hxx
+++ b/sw/source/core/inc/ascharanchoredobjectposition.hxx
@@@ -140,7 -140,7 +140,11 @@@ namespace objectpositionin
Point GetAnchorPos() const;
// calculated relative position to base line for object position ty
++<<<<<<< HEAD
+
++=======
+
++>>>>>>> Removal of bogus comments in writer module
SwTwips GetRelPosY() const;
// determined object rectangle including spacing for object position
diff --cc sw/source/core/inc/frame.hxx
index 664f28b,94db9cc..0000000
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@@ -248,6 -250,9 +248,12 @@@ enum MakePageTyp
MAKEPAGE_NOSECTION // Don't create section frames
};
++<<<<<<< HEAD
++=======
+ // #i28701# - replaced by new class <SwSortedObjs>
+ //typedef SdrObject* SdrObjectPtr;
+ //SV_DECL_PTRARR(SwDrawObjs,SdrObjectPtr,1,1);
++>>>>>>> Removal of bogus comments in writer module
class SwFrm: public SwClient, public SfxBroadcaster
{
(END)
and git status
shows this:
victor@victor-laptop:~/git/libo/clone/writer$ git status
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: sw/source/core/inc/SwXMLBlockExport.hxx
#
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: sw/source/core/doc/docdesc.cxx
# both modified: sw/source/core/frmedt/fews.cxx
# both modified: sw/source/core/inc/UndoCore.hxx
# both modified: sw/source/core/inc/ascharanchoredobjectposition.hxx
# both modified: sw/source/core/inc/frame.hxx
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# 0001-Removal-of-bogus-comments-in-writer-module.patch
If I try to resolve conflicts by manually editing those files, git tells me that my master has diverged from origin/master. This situation continues in a cycle. Please help me out. What can the problem be and how can I resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Git 警告您您的分支已偏离 master,因为您的分支已偏离 master。
如果我对情况的理解正确的话,首先您在
master
之上创建了一个新的提交(我们称之为B
)(我们称之为A
) 。 Git 正确地说,您比origin
的master
早了一次提交。与此同时,其他人在
origin
的master
之上添加了新的提交:此时,您的
master
和origin
> 的master
出现了分歧。您有一个origin/master
没有的提交,而origin/master
有 3 个您没有的提交。这 3 个之一甚至可能是您发送的补丁(我在您的 git status 输出中看到由 git format-patch 创建的文件,所以我猜您将其发送为补丁);应用补丁不会创建完全相同的提交(至少提交者名称和时间戳会不同)。当您执行
git pull
时,git 必须将您的提交 (B
) 与您没有的提交合并,创建一个合并提交(我们称之为F
):请再次注意,
origin/master
没有您的提交(这次是B
和F
)。如果有人向origin/master
添加新的提交,您将不得不再次合并。现在,如何摆脱这种局面呢?有几种方法。一种是将您的更改推送到
origin
,因此现在它拥有您拥有的一切。另一种方法是放弃您的提交并将您的master
重置为origin/master
。第三种方法是在origin/master
之上重新调整您的提交。如果我猜对了,您通过 git format-patch 通过电子邮件发送了更改,并且它们已经应用,那么在您的情况下,最好的方法是重置您的 master到
origin/master
。为了避免将来出现此问题,最好在单独的分支中工作,并在从上游拉取更改之前切换回master
。Git is warning you that your branch has diverged from master because your branch has diverged from master.
If I understood the situation correctly, first you created a new commit (let's call it
B
) on top ofmaster
(let's call itA
). Git says correctly that you are one commit ahead oforigin
'smaster
.Meanwhile, other people added new commits on top of
origin
'smaster
:At this point, your
master
andorigin
'smaster
have diverged. You have one commit whichorigin/master
does not have, andorigin/master
has 3 commits which you do not have. One of these 3 might even be the patch you sent (I see the file created bygit format-patch
in yourgit status
output, so I am guessing you sent it as a patch); applying a patch will not create the exact same commit (at least the commiter name and timestamp will be different).When you do a
git pull
, git has to merge your commit (B
) with the commits you do not have, creating a merge commit (let's call itF
):Note that, again,
origin/master
does not have your commits (B
andF
this time). If anyone adds new commits toorigin/master
, you will have to merge again.Now, how to get out of this situation? There are several ways. One is to push your changes to
origin
, so now it has everything you have. Another is to abandon your commits and reset yourmaster
toorigin/master
. And a third one is to rebase your commits on top oforigin/master
.If I am guessing correctly that you sent your changes by email via
git format-patch
and they were already applied, the best way out in your case would be to reset yourmaster
toorigin/master
. To avoid this problem in the future, it is best to work in a separate branch and switch back tomaster
before pulling changes from upstream.