0

While working on a feature I stashed my changes at times, when I thought there is a lot things done.

Now I realised I need some code that I implemented, stashed, then removed and stashed again. So I currently don't have it, but I have it in one of my shashed versions.

So I can't just apply that stashed version, because there is a lot of things I don't need to be merged. Is there a way to merge it manually?

Basically, I can see git diff between current version and stashed one with:

git diff stash@{n}

But how can I use a merge tool (I usually use "meld") to merge?

"Meld" is not a must.

rightaway717
  • 2,631
  • 3
  • 29
  • 43

2 Answers2

0

Just do git stash apply (or pop), and it brings the changes into you working directory. Then you could undo undesired changes and commit.

kan
  • 28,279
  • 7
  • 71
  • 101
  • If I do that, its gonna be a hell to remove undesired changes. Theres is a lot of stuff in lots of files. So this is not an option – rightaway717 Jan 22 '15 at 14:25
  • @rightaway717 use hunk-level `git add` (or `git gui`) to stage into the index a changeset you want to commit and commit, then checkout to undo all uncommited changes. The situation you are - it is nothing to do with merge (conflict resolution). You just want to pick changes for committing. – kan Jan 22 '15 at 18:49
  • Isn't picking changes for commiting and inserting them into another revision called merging? I'm not a native English speaker, but I even checked wiki and I got an idea that this exactly what manual merging is, or at least a variant of it. I'm not talking about auto-merging, which is just exactly what you are talking about. Anyway, I appreciate your taking time to answer the question. – rightaway717 Jan 23 '15 at 05:10
  • @rightaway717 But you don't have another revision, just stashed changes. – kan Jan 23 '15 at 10:22
0

This is fairly simple

  • checkout your branch and make sure there are no unchanged files
  • apply the stash version you need, say n, with "git stash apply stash@{n}"
  • now check the changes, keep the ones you need and remove the others; Meld should work all right here
  • once you are sure you have the subset of changes you need, add and commit all the files

PS: Just to clarify, I think you meant to say using Meld as a diff-tool, and not merge tool. There is no merge happening in the question.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • Well, maybe I'm mistaken in terms. But when I use Meld, I drag changes from one side to another, so to me it looks like merging, doesn't it? Or is it called some other way? As for your answer, I appreciate your time. But what I was looking for is e a way to just open current and stashed version in some diff (merge) tool and drag changes back and forth like I want. – rightaway717 Jan 22 '15 at 14:23