Tamud Gu
Tamud Gu

Reputation: 31

error after git stash pop twice

I hava a file A and 2 stash both modified file A, then I ran the command 'git stash pop' twice.

The result is first stash popped successfully,but second stash occur an error like below:

error: Your local changes to the following files would be overwritten by merge: A

Please, commit your changes or stash them before you can merge. Aborting

I need both the 2 stash, and I dont want a commit after first stash pop. So how can I fix this problem?Is There a way for me to merge this 2 stash and then just pop once to meet my request?

Upvotes: 1

Views: 739

Answers (3)

Joey Dorrani
Joey Dorrani

Reputation: 247

An indication of this happening is because one cannot merge when there are local modifications. Git tries to protect you from losing those changes..

I've read that one of the solutions is to (1) commit the local changes or (2) stash them temporary or (3) discard them.

Perhaps take a look at this link for further information: Resolving Git merge conflicts.

Upvotes: 0

pratZ
pratZ

Reputation: 3356

You can not do that without committing your changes.

  1. pop first stash.

    git stash pop
    
  2. add and Commit

    git commit -m 'temp commit'
    
  3. pop second stash

    git stash pop
    
  4. add and amend last commit

    git commit --amend --no-edit
    
  5. undo last commit and bring last commit changes to unstaged area

    git reset HEAD~1
    

Upvotes: 3

Martin Bobák
Martin Bobák

Reputation: 1

You first need to handle changes on file A from first pop. Commit them and do second pop.You can then amend changes to previous commit or do a new one.

Upvotes: 0

Related Questions