1

Im not able to do a GIT stash because its saying i need to merge first. There are a few files that need to be merged. But my issue is i don't want to push those changes yet. I've tried doing git stash but it complains that some files are not merged yet.

However, i don't want to merge the files because I want to stash these changes for like 3 weeks while i do other work. How can i Stash my changes and simply checkout cleanly without doing a commit ?

here is what i have tried:

git stash save "my work"
src/com/core/HomePageActivity.java: needs merge
src/com/core/PageActivity.java: needs merge
src/com/core/analytics/PageMaker.java: needs merge

results of git status:

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

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

    modified:   lint.xml
    modified:   src/com/lib/Signal.java
    modified:   src/com/lib/Report.java
    modified:   src/com/lib/core/Menu.java

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

    both modified:      src/com/core/HomePageActivity.java
    both modified:      src/com/core/PageActivity.java
    both modified:      src/com/core/analytics/PageNameMaker.java
    both modified:      src/com/store/MapActivity.java

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/com/score/TiledActivity.java
        modified:   src/com/core/store/Action.java
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • 1
    did you try to perform a merge which didn't exit clearly? What's the output of the `git status`? – Isantipov Oct 15 '14 at 15:21
  • Looks similar to http://stackoverflow.com/questions/12139812/why-git-stash-cannot-abandon-the-changes-made-just-now - probably the result of a merge still in progress. – nwinkler Oct 15 '14 at 15:21
  • I wasn't specifically doing a merge. When i pulled down i had conflicts. I fixed the conflicts but just kept on working after without commit because i did not want to commit those changes i want them local. so if i do "git merge --abort" and then git stash will it save all the changes i did before and after i pulled ? – j2emanue Oct 15 '14 at 15:30
  • `git pull` is doing an automatic merge after fetching the changes. Since you've made changes after starting the merge, I'm not sure whether there's a clean way of returning to the state before the merge AND keeping the changes you have made in the meantime. – nwinkler Oct 15 '14 at 15:34
  • ok can you recommend what i should have done instead ? – j2emanue Oct 15 '14 at 15:37
  • If you do a `git pull` and the message shows you that there were conflicts, don't continue your normal work. Either resolve the conflicts and commit the resulting changes, or abort the merge and then rethink your approach (committing your changes first, then rebase, or stash your changes, then merge again). – nwinkler Oct 15 '14 at 15:39
  • 1
    This is another reason not to use `git pull`, at least if you're a "git newbie". The `pull` script is quite fancy but at its core it just runs `git fetch` and then `git merge`, and when the `git merge` step goes wrong, since you haven't learned `git merge` you are stuck in this limbo. Read up on using `git merge`, and if you are not ready to merge now, read up on `git merge --abort` which terminates the attempt to merge and puts things back the way they were before the attempt. – torek Oct 15 '14 at 15:53
  • 1
    @j2emanue Are you aware that commiting is not the same as pushing? You can commit your changes, create branches, work as long as you want but you don't have to push any of that. – musiKk Oct 15 '14 at 16:01
  • git merge --abort will work fine if you do not have uncommitted changes. But since you do not want to commit, it may not work correctly. http://git-scm.com/docs/git-merge – DolphinJava Oct 15 '14 at 16:02

1 Answers1

0

git merge --abort may not be able to reconstruct the pre-merge state if there are uncommitted worktree changes present. To circumvent this, you can do following

You can commit your uncommitted changes. The changes will stay local. Thereafter, you can use

  git merge --abort 

which according to http://git-scm.com/docs/git-merge will now attempt to reconstruct the pre-merge state. It may become successful now because now you do not have anything uncommitted.

Once this is done, you can revert your commit and stash your changes.

DolphinJava
  • 2,682
  • 1
  • 23
  • 37