Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git stash pop with local changes #582

Merged
merged 1 commit into from
Dec 22, 2016
Merged

Conversation

josephfrazier
Copy link
Collaborator

When there are local changes to a file, and a git stash is popped that
contains other changes to that same file, git fails as follows:

$ git stash pop
error: Your local changes to the following files would be overwritten by merge:
        src/index.js
Please commit your changes or stash them before you merge.
Aborting
$

This change adds a rule that corrects this problem as suggested here:

$ git stash pop
error: Your local changes to the following files would be overwritten by merge:
        src/index.js
Please commit your changes or stash them before you merge.
Aborting
$ fuck
git add . && git stash pop && git reset . [enter/↑/↓/ctrl+c]
Auto-merging src/index.js
On branch flow
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   src/index.js

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   src/index.js

Dropped refs/stash@{0} (f94776d484c4278997ac6837a7b138b9b9cdead1)
Unstaged changes after reset:
M        src/index.js
$

When there are local changes to a file, and a git stash is popped that
contains other changes to that same file, git fails as follows:

    $ git stash pop
    error: Your local changes to the following files would be overwritten by merge:
            src/index.js
    Please commit your changes or stash them before you merge.
    Aborting
    $

This change adds a rule that corrects this problem as suggested [here]:

    $ git stash pop
    error: Your local changes to the following files would be overwritten by merge:
            src/index.js
    Please commit your changes or stash them before you merge.
    Aborting
    $ fuck
    git add . && git stash pop && git reset . [enter/↑/↓/ctrl+c]
    Auto-merging src/index.js
    On branch flow
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)

            modified:   src/index.js

    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

            modified:   src/index.js

    Dropped refs/stash@{0} (f94776d484c4278997ac6837a7b138b9b9cdead1)
    Unstaged changes after reset:
    M        src/index.js
    $

[here]: https://stackoverflow.com/questions/15126463/how-do-i-merge-local-modifications-with-a-git-stash-without-an-extra-commit/15126489#15126489
@coveralls
Copy link

coveralls commented Dec 11, 2016

Coverage Status

Coverage increased (+0.03%) to 93.341% when pulling 8c62706 on josephfrazier:git_stash_pop into 6baa7f6 on nvbn:master.

@nvbn
Copy link
Owner

nvbn commented Dec 22, 2016

Thanks!

@nvbn nvbn merged commit e313ff7 into nvbn:master Dec 22, 2016
@josephfrazier josephfrazier deleted the git_stash_pop branch January 11, 2017 03:11
riley-martine pushed a commit to riley-martine/thefuck that referenced this pull request Dec 7, 2023
Fix `git stash pop` with local changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants