0

I'm trying to restore my unsaved files (stashed files)

I had to make a small code change for that first my remote is one commit a head with 1 file change(file1). I need to update my local first with remote and push my changes, for that I have to stash my changes in my local as I have the same file modified (file1) in my local. So I have done the following.

$git stash
  Saved working directory and index state WIP on dev: 4eb5499

$git pull
  Updating 4eb5499..db82e7c
  Fast-forward

$git add file2 //this is different file.
$git commit
$git push

//with this done on my dev branch I also want to update my master branch with remote

So

$git checkout master
  Switched to branch 'master'
  Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.

$git pull 
  Updating 4eb5499..db82e7c
  Fast-forward

$git merge dev //to update my changes on master
$git push

  with this done my remote is updated with my changes. both on dev/master branch.

  Now I have switched my branch again. 

$git checkout dev
$git stash pop
  Auto-merging **file1**
  CONFLICT (content): Merge conflict in **file1**

  As i have done
$git status

  On branch dev
  Your branch is up-to-date with 'origin/dev'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

   So I have performed the following
$ git reset HEAD

$ git status
  On branch dev
  Your branch is up-to-date with 'origin/dev'.

  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)

$ git stash list
  stash@{0}: WIP on dev: 4eb5499 //I want the changes which are here.
  stash@{1}: WIP on master: 9dac6b5

$ git stash pop
  error: Your local changes to the following files would be overwritten by merge:

I just want my stashed files to be used again.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Arun
  • 300
  • 2
  • 13

2 Answers2

1

This occurs because the stash commit that you are attempting to apply via git stash pop conflicts with the current work-tree.

Many people run git stash instead of git commit in the mistaken belief that git stash does not make a commit. This is not the case: in fact, git stash makes at least two commits. (Depending on the flags you give git stash, it may make three commits instead of two.) The thing that is the most special about the commits that git stash makes is that they are on no branch at all.

Nonetheless, they are still commits, just like other commits. When you go to "pop" a stash, this simply means git stash apply && git stash drop. That is, you are telling Git to apply the stash to your current work-tree contents. If Git believes this went well, you then tell Git to drop the stash, i.e., discard the stash commits.

In some cases, the stash commits will not apply cleanly, and you will get a merge conflict, just as you would if you were running git merge or git cherry-pick. You must resolve this merge conflict, just as you would any other merge conflict. Note that in this case Git has not dropped the stash: git stash list will still show it.

For more about resolving stash conflicts, see How to resolve git stash conflict without commit?

torek
  • 448,244
  • 59
  • 642
  • 775
0

I found that git has added few lines on the files, which looks like there is some bug in the files (by compiler), So went into file and deleted the lines added by git

<<<<<<< Updated upstream

between this
code may be replicated again please check and delete.

=======
>>>>>>> Stashed changes
Arun
  • 300
  • 2
  • 13