Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
On Tue, Dec 29, 2015 at 11:04:20AM -0800, Junio C Hamano wrote: > [...] > In the above, I suggested to "git reset" when there is no conflict. > I think this line of thinking can be followed even further to > selectively reset the paths that were cleanly merged (which is added > by the call to merge-recursive), leaving _only_ the conflicted paths. > > Would that give us a better outcome? I dunno. Yes, I think that is the only sensible change to make. The only other option (besides leaving it as-is) would be to unstage _everything_ leaving conflict-marker cruft in the working tree, but no conflicts in the index. I think that's a mistake, but I won't repeat the arguments I left elsewhere in the thread. So it's probably something like: git ls-files -t | grep -v ^M | cut -d ' ' -f2- | xargs git reset -- (modulo some quoting robustness improvements). But I guess we'd want to preserve any modifications that were originally in the index. So maybe the intersection of the files above and the output of "git diff-tree --name-only" on the stash commit. There are probably some corner cases to look at (e.g., with "--index"). As I said, I'm not planning to work on it anytime soon, but the above may give some clues to somebody who wants to pursue it. -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
On Tue, Dec 29, 2015 at 09:20:38PM +, Alan Mackenzie wrote: > > Yeah, I think I agree. But keep in mind that we have to mention the > > conflicts _somewhere_, so we're going to touch the index regardless (and > > the user is going to have to erase the conflicts in the index > > eventually, either with `git add` or `git reset`). > > When the stash consists entirely of changes in the working directory, > and "git stash pop" has conflicts, why can't these conflicts simply be > marked by "" (etc.) in the working directory, leaving the index > unchanged? The index is left unchanged when there are no conlicts. I don't think that's a good idea. Git always marks conflicts in the index for other operations. Besides being inconsistent with the rest of git, it drops useful information that other tools can use. For example, one cannot "git checkout --conflict=diff3" afterwards, or use "git mergetool" to kick off a third-party merge tool. Not to mention that the information is lost to the user themselves. If we touched 10 files and 2 had conflicts, there is now no way for the user to ask "where were the conflicts?". They can either find the stash output in their terminal scrollback, or grep for things that look like conflict markers. -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
Hello, Jeff. On Tue, Dec 29, 2015 at 02:53:30AM -0500, Jeff King wrote: > On Thu, Dec 24, 2015 at 09:20:38AM +, Alan Mackenzie wrote: > > > It seems to be a side effect of merge-recursive to stage the results, > > > and in the no-conflict path we explicitly reset the index. For the > > > conflicting case, it's trickier, because we would want to retain the > > > unmerged entries. > > > So I agree it's kind of weird, but the conflicting case is inherently > > > going to touch the index, and you'd generally have to `git add` to mark > > > the resolutions (but if you really want to just touch the working tree, > > > you'd need to `git reset`). > > From the point of view of a user, this is suboptimal. git stash is an > > abstraction: the preservation of uncomitted changes for later. Staging > > previously unstaged changes with git stash pop severely damages this > > abstraction. > Yeah, I think I agree. But keep in mind that we have to mention the > conflicts _somewhere_, so we're going to touch the index regardless (and > the user is going to have to erase the conflicts in the index > eventually, either with `git add` or `git reset`). When the stash consists entirely of changes in the working directory, and "git stash pop" has conflicts, why can't these conflicts simply be marked by "" (etc.) in the working directory, leaving the index unchanged? The index is left unchanged when there are no conlicts. > > Are there any prospects of this getting fixed? > Somebody needs to write a patch. I am not 100% convinced that it > _should_ be fixed, but I am leaning that way. But I am not planning to > work on it myself anytime soon. The best way to get more discussion > going is to post a patch. :) Hmm. I would very much prefer to remain just a user of git. > -Peff -- Alan Mackenzie (Nuremberg, Germany). -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
Jeff King writes: > Yeah, I think I agree. But keep in mind that we have to mention the > conflicts _somewhere_, so we're going to touch the index regardless (and > the user is going to have to erase the conflicts in the index > eventually, either with `git add` or `git reset`). I do not think there is much we can do at this point in time (but notice that I did say "much", and didn't say "anything"). The way we replay any potentially conflicting change and present the result to the end user in Git is uniformly to add the cleanly applied parts to the index while leaving the conflicted ones as unmerged index entries, but "git stash apply/pop" does not follow this pattern. I think this is partly because the command is also used to "stash away" a work-in-progress changes to the index, and avoiding to touch the index with the changes in the working tree would more closely match the behaviour of the command when there is no conflict. I notice that I said the same thing long time ago, i.e. in the initial round of review: http://article.gmane.org/gmane.comp.version-control.git/50749 | However, I think it is a bit counterintuitive to update the | working tree change to the index if the merge did not conflict. | It might be better to run an equivalent of "git reset", so that | after "git save restore", the user can say "git diff" (not "git | diff HEAD") to view the local changes. Perhaps... In the above, I suggested to "git reset" when there is no conflict. I think this line of thinking can be followed even further to selectively reset the paths that were cleanly merged (which is added by the call to merge-recursive), leaving _only_ the conflicted paths. Would that give us a better outcome? I dunno. >> Are there any prospects of this getting fixed? > > Somebody needs to write a patch. I am not 100% convinced that it > _should_ be fixed, but I am leaning that way. But I am not planning to > work on it myself anytime soon. The best way to get more discussion > going is to post a patch. :) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
On Thu, Dec 24, 2015 at 09:20:38AM +, Alan Mackenzie wrote: > > It seems to be a side effect of merge-recursive to stage the results, > > and in the no-conflict path we explicitly reset the index. For the > > conflicting case, it's trickier, because we would want to retain the > > unmerged entries. > > > So I agree it's kind of weird, but the conflicting case is inherently > > going to touch the index, and you'd generally have to `git add` to mark > > the resolutions (but if you really want to just touch the working tree, > > you'd need to `git reset`). > > From the point of view of a user, this is suboptimal. git stash is an > abstraction: the preservation of uncomitted changes for later. Staging > previously unstaged changes with git stash pop severely damages this > abstraction. Yeah, I think I agree. But keep in mind that we have to mention the conflicts _somewhere_, so we're going to touch the index regardless (and the user is going to have to erase the conflicts in the index eventually, either with `git add` or `git reset`). > Are there any prospects of this getting fixed? Somebody needs to write a patch. I am not 100% convinced that it _should_ be fixed, but I am leaning that way. But I am not planning to work on it myself anytime soon. The best way to get more discussion going is to post a patch. :) -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
Hello, Jeff. On Tue, Dec 22, 2015 at 04:30:33AM -0500, Jeff King wrote: > On Tue, Dec 22, 2015 at 09:17:38AM +0100, Dennis Kaarsemaker wrote: > > On ma, 2015-12-21 at 14:29 +, Alan Mackenzie wrote: > > > Hello, git project. > > > Last night, whilst clearing out a stale "stash stack", I did "git stash > > > pop". There were conflicts in two files. > > > However, all the popped files became staged. This doesn't normally > > > happen. > > > It was intensely irritating, and required me to do "git reset HEAD" on > > > each of the files, none of which I wanted to commit. > > > I searched the git-stash man page for this scenario, but found nothing > > > about it. > > > Surely staging all the files is a bug? > > That depends. A stash is two commits: one for all changes that were in > > the index when you ran 'git stash save' and one for all changes not yet > > in the index. When you pop the stash, these then get restored as staged > > resp. unstaged changes. So if your changes are now all staged, I'd > > wager that they were staged when you ran git stash save. > No, I think there's something else going on. Try this: > git init repo && > cd repo && > echo base >one && > echo base >two && > git add . && > git commit -m base && > echo stash >one && > echo stash >two && > git stash && > echo "==> No conflicts, nothing staged" > git stash apply && > git reset --hard && > echo changes >two && > git commit -am changes && > echo "==> Conflict stages non-conflicting file 'one'" > ! git stash apply && > git status Thanks for creating a reproducible test case for me! > It seems to be a side effect of merge-recursive to stage the results, > and in the no-conflict path we explicitly reset the index. For the > conflicting case, it's trickier, because we would want to retain the > unmerged entries. > So I agree it's kind of weird, but the conflicting case is inherently > going to touch the index, and you'd generally have to `git add` to mark > the resolutions (but if you really want to just touch the working tree, > you'd need to `git reset`). >From the point of view of a user, this is suboptimal. git stash is an abstraction: the preservation of uncomitted changes for later. Staging previously unstaged changes with git stash pop severely damages this abstraction. Are there any prospects of this getting fixed? > -Peff -- Alan Mackenzie (Nuremberg, Germany). -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
On Tue, Dec 22, 2015 at 09:17:38AM +0100, Dennis Kaarsemaker wrote: > On ma, 2015-12-21 at 14:29 +, Alan Mackenzie wrote: > > Hello, git project. > > > > Last night, whilst clearing out a stale "stash stack", I did "git stash > > pop". There were conflicts in two files. > > > > However, all the popped files became staged. This doesn't normally happen. > > It was intensely irritating, and required me to do "git reset HEAD" on > > each of the files, none of which I wanted to commit. > > > > I searched the git-stash man page for this scenario, but found nothing > > about it. > > > > Surely staging all the files is a bug? > > That depends. A stash is two commits: one for all changes that were in > the index when you ran 'git stash save' and one for all changes not yet > in the index. When you pop the stash, these then get restored as staged > resp. unstaged changes. So if your changes are now all staged, I'd > wager that they were staged when you ran git stash save. No, I think there's something else going on. Try this: git init repo && cd repo && echo base >one && echo base >two && git add . && git commit -m base && echo stash >one && echo stash >two && git stash && echo "==> No conflicts, nothing staged" git stash apply && git reset --hard && echo changes >two && git commit -am changes && echo "==> Conflict stages non-conflicting file 'one'" ! git stash apply && git status It seems to be a side effect of merge-recursive to stage the results, and in the no-conflict path we explicitly reset the index. For the conflicting case, it's trickier, because we would want to retain the unmerged entries. So I agree it's kind of weird, but the conflicting case is inherently going to touch the index, and you'd generally have to `git add` to mark the resolutions (but if you really want to just touch the working tree, you'd need to `git reset`). -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
On ma, 2015-12-21 at 14:29 +, Alan Mackenzie wrote: > Hello, git project. > > Last night, whilst clearing out a stale "stash stack", I did "git stash > pop". There were conflicts in two files. > > However, all the popped files became staged. This doesn't normally happen. > It was intensely irritating, and required me to do "git reset HEAD" on > each of the files, none of which I wanted to commit. > > I searched the git-stash man page for this scenario, but found nothing > about it. > > Surely staging all the files is a bug? That depends. A stash is two commits: one for all changes that were in the index when you ran 'git stash save' and one for all changes not yet in the index. When you pop the stash, these then get restored as staged resp. unstaged changes. So if your changes are now all staged, I'd wager that they were staged when you ran git stash save. -- Dennis Kaarsemaker www.kaarsemaker.net -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
Alan Mackenzie wrote: on Mon, 21 Dec 2015 14:29:54 > Hello, git project. > Last night, whilst clearing out a stale "stash stack", I did "git stash > pop". There were conflicts in two files. > However, all the popped files became staged. This doesn't normally happen. > It was intensely irritating, and required me to do "git reset HEAD" on > each of the files, none of which I wanted to commit. > I searched the git-stash man page for this scenario, but found nothing > about it. > Surely staging all the files is a bug? Sorry, forgot to mention I'm using git 2.4.10 on GNU/Linux. -- Alan Mackenzie (Nuremberg, Germany). -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
"git stash pop" is doing an unwanted "git add" when there are conflicts.
Hello, git project. Last night, whilst clearing out a stale "stash stack", I did "git stash pop". There were conflicts in two files. However, all the popped files became staged. This doesn't normally happen. It was intensely irritating, and required me to do "git reset HEAD" on each of the files, none of which I wanted to commit. I searched the git-stash man page for this scenario, but found nothing about it. Surely staging all the files is a bug? -- Alan Mackenzie (Nuremberg, Germany). -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html