为什么本地更改会被合并覆盖?

时间:2017-01-15 12:56:22

标签: git git-merge

我有下一个本地更改:

diff --git a/lib/Art.pm b/lib/Art.pm
index c8fd249..4bd479f 100644
--- a/lib/Art.pm
+++ b/lib/Art.pm
@@ -61,6 +61,7 @@ sub startup {


     $self->hook( around_action  =>  \&Art::Controller::_log_request        );
+    $self->hook( around_action  =>  \&Art::Controller::_store_referral     );
     $self->hook( around_action  =>  \&Art::Controller::_json_as_urlencoded );
     $self->hook( after_dispatch =>  \&Art::Controller::_mail_exception     );
     # NOTICE: before_render is called even before rendering included template

并且存储中有下一个更改:

diff --git a/lib/Art.pm b/lib/Art.pm
index 0dde0ec..cff11c9 100644
--- a/lib/Art.pm
+++ b/lib/Art.pm
@@ -32,6 +32,7 @@ sub startup {
     push @{ $self->plugins->namespaces }, __PACKAGE__ .'::Plugin';
     $self->plugin( Config =>  { file => 'conf/' .$self->moniker .'.conf' } );
     $self->plugin( 'TagHelpers::FetchPanel' );
+    $self->plugin( 'UserReferral',  key => 'r' );

     # default_page is used in redirections. Redirect to site root by default

正如您所看到的,这些更改并不重叠。

为什么我在尝试应用此存储时出现此错误?

error: Your local changes to the following files would be overwritten by merge:
    lib/Art.pm

有没有办法在没有此错误的情况下应用此补丁?

1 个答案:

答案 0 :(得分:1)

  

有没有办法在没有此错误的情况下应用此补丁?

您收到此错误的原因是,正如错误消息所示,您对文件lib/Art.pm进行了本地更改,这些更改将被合并覆盖。因此,您应该做的第一件事是通过以下方式提交您的本地更改:

git add lib/Art.pm
# and commit any other work you want
git commit -m 'local changes to Art.pm'

在此之后,您可以通过以下方式应用存储:

git stash apply

请注意,您仍可能会遇到合并冲突。如果你这样做,那只意味着Git非常谨慎,并且不想假设它应该使用哪个Art.pm的最终版本。如果发生冲突,此文件将包含类似<<<<====的冲突标记。解决冲突,并再次提交以完成应用存储。