0

I have next local changes:

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 

And has next changes in the stash:

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 

As you can see these changes are not overlap.

Why I get this error when try to apply this stash?

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

Is there a way to apply this patch without this error?

3
  • A Git stash contains two (or sometimes three) commits and git stash show shows only differences computed through one of these two commits, specifically the work-tree commit. It seems likely that the conflict occurs through the other (index) commit. This would occur if you apply the stash with --index, which uses git read-tree rather than git read-tree --reset. If so, simply omitting --index so that Git discards the conflicting saved index should do it. Commented Jan 15, 2017 at 14:17
  • @torek I suspected there would be an alternative to the answer I gave, and you actually came to mind. In practice, I probably wouldn't get as deep as worrying about which stash commit was the culprit. Would my answer go wrong in any case? Commented Jan 15, 2017 at 14:35
  • @TimBiegeleisen: Making a commit will usually allow you to apply the stash even with --index. You can still get merge conflicts, although in this case I don't expect there would be any; and if the merge conflicts are severe, you might have to use git stash branch or equivalent to apply while still preserving the separate index and work-tree. Bottom line is that with --index, even making a new commit isn't guaranteed to suffice, but it will usually work. Applying without --index is easier, in a fundamental sense, as it gives Git permission to discard most of the index commit. Commented Jan 15, 2017 at 15:15

1 Answer 1

1

Is there a way to apply this patch without this error?

You are getting this error because, as the error message says, you have local changes to the file lib/Art.pm which would be overwritten by the merge. So, the first thing you should do is commit your local changes via:

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

After this, you can apply the stash via:

git stash apply 

Note that you still may get merge conflicts here. If you do, it just means that Git was being cautious and did not want to assume which final version of Art.pm it should use. In the event of conflicts, this file would be peppered with conflict markers looking like <<<< and ====. Resolve the conflicts, and make another commit to finish applying the stash.

Sign up to request clarification or add additional context in comments.

4 Comments

Ah, sure. But if I remember right it is sufficient to just add file into index without committing it
But then how would this work out? You would have a working version from the stash, and a staged version from somewhere else. How would you resolve this?
In this case no merge conflicts. Changes are just applied to wc and finish. Stashed changes leaved intact
There are multiple ways we could have dealt with this, but this is probably my first choice. You can always squash the two commits together by committing via git commit --amend to make a single commit.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.