Proposed git mv behavioral change
Quoted 13 lines · Wincent Colaiuta
Quoted 1 line · Michael Witten
Ah. Basically my 'pseudo-code' is correct, but redundant.
If I understood the original poster's proposal then I don't think your code does what he asked for:
Quoted 7 lines
What you want to happen is the following:
git show HEAD:A.txt >
path/B.txt
git addpath/B.txt
mv A.txt B.txt
git rm A.txt
Quoted 6 lines
Quoted 1 line
Is this correct?
Here you're copying the content of A.txt as it was in the last (HEAD) commit, but from what the poster said he wants the content of A.txt as it is staged in the index (that is, there may be staged but uncomitted changes).
You took the words right out of my mouth! :)
Yeah, I noticed the problem with using HEAD, but the other problem is that this would change the contents of the file in the working directory file, which I don't want. Thus, putting the contents of the file as it is in the index into the working directory wouldn't be correct either. In addition, I'm not quite sure where that "mv A.txt B.txt" came from, since we're supposed to be moving A.txt to path/B.txt...
Quoted 6 lines
Quoted 4 lines
Better:
Quoted 2 lines
mv A.txt
path/B.txt
Point the index entry for A.txt topath/B.txtYes, that is basically what he was asking for, as I read it.
Yep! I was going to respond to your (Michael's) original message saying exactly that. :)
Quoted 8 lines · Jeff King
Quoted 3 lines
Hrm. So you _do_ want to do an index-only move of A to B, in which case the suggestion of a "git-mv --cached" seems sensible. Though I'm curious why you want that.
I agree that git-stash can be used in this workflow but I can also imagine cases where the proposed "git-mv --cached" might be a bit nicer.
As Shawn said, --cached wouldn't be entirely accurate as the file in the working directory is being moved as well.
git-stash has been suggested to me numerous times, but I really feel that there's no need to use it in this case - if the git mv command gave adequate control to the user, it would be unnecessary.
Quoted 5 lines
I'm thinking of occasions where you just want to do something like:
git mv --cached foo bar
git add --interactive bar
I think it would be the other way around, since the only time this change would effect anything is when there are changes still waiting to be staged.
Are you talking about REALLY only changing the index? I can't think of why you'd want to do this either... After all, wouldn't there be no bar file to do git add --interactive on? In addition, I don't think giving --interactive a filename is meaningful...
Quoted 3 lines
I'm not sure the proposed "--cached" switch should ever be the default -- would need to ponder that one -- but I do think the switch would be a nice addition.
Yeah, that is one thing I was wondering. It would break compatibility, but would it be enough to put a note about that in the announcements for a release? Could you make the change at a release when the interface isn't guaranteed to be the same, or is this practice only done with libraries?
It might be interesting to do some sort of survey of whether people depend on this behavior. It seems pretty inconsistent with how git works otherwise, and I'd be surprised if a lot of people expect it (kinda like the Spanish Inquisition :-P).
Thanks,
Ari
Quoted 3 lines · Ari Entlich
git-stash has been suggested to me numerous times, but I really feel that there's no need to use it in this case - if the git mv command gave adequate control to the user, it would be unnecessary.
Yes, now that I understand what you're doing, git-stash is probably overkill. It's great if you really want to put aside your current state and do some other, totally unrelated work.
But in this case, you are talking about tools for managing the index correctly, which is a totally different use case.
Quoted 5 lines
Quoted 1 line
git mv --cached foo bar
Are you talking about REALLY only changing the index? I can't think of why you'd want to do this either... After all, wouldn't there be no bar file to do git add --interactive on? In addition, I don't think giving --interactive a filename is meaningful...
Originally I had thought git-mv --cached would be useful (and a nice orthogonal design), but it really _does_ seem useless, since it's awkward to get your working tree changes into the index without actually moving the working tree file.
Quoted 4 lines
It might be interesting to do some sort of survey of whether people depend on this behavior. It seems pretty inconsistent with how git works otherwise, and I'd be surprised if a lot of people expect it (kinda like the Spanish Inquisition :-P).
The best way to get comments is to make a patch.
As for inconsitency of git-mv, it has always been a bit of an odd duck. I'm fairly certain neither Linus nor Junio actually use it, preferring instead to make all changes to the working tree and then update the index manually. I even seem to recall Linus arguing that git-mv was stupid and unnecessary a long time ago, but I could be wrong.
-Peff
Quoted 10 lines · Ari Entlich
Quoted 5 lines
I'm thinking of occasions where you just want to do something like:
git mv --cached foo bar
git add --interactive barI think it would be the other way around, since the only time this change would effect anything is when there are changes still waiting to
be staged.
Well, my point was that sometimes you want to rename a dirty file *right now* without having your modifications staged in the index yet, and only later go ahead and stage the hunks (or the whole file) when they're ready.
Basically, without this feature you have to manually unstage the stuff that you don't want staged:
[hack on dirty foo]
git mv foo bar
[oops... you just staged unfinished changes]
git reset HEAD bar
[hack until bar is ready]
git add bar
So in order to unstage the stuff that wasn't ready you unstaged the whole file and had to re-add it later, in which case what was the point of using "git-mv" in the first place? You may as well have just done:
[hack on dirty foo]
mv foo bar
[hack until bar is ready]
git rm foo
git add bar
The other alternative is to use git-stash:
[hack on dirty foo]
git stash
git mv foo bar
git stash apply
[hack until bar is ready]
git add bar
So, yes, you can do this with git-stash. It just means that "git-mv -- cached" would be a convenient short-cut.
Quoted 1 line
Are you talking about REALLY only changing the index?
No, sorry, I didn't make that clear. I meant that "git mv --cached foo bar" would have the following effect (which if I understand it correctly is basically what you proposed in your first email):
1. Copying "foo" directly to "bar" (even if dirty).
2. When adding "bar" to the the index add the blob corresponding to "foo" as it is staged in the index (or at the HEAD if there are no staged changes).
3. Removing the old file "foo".
The actual mechanics of this don't matter; those are just the perceived effects. You could get exactly the same perceived effects by doing it this way:
1. Creating a new file (or overwriting an existing one) named "bar", whose contents would match those of the file "foo" not as it appears in the working tree but as it is staged in the index.
2. If "foo" has unstaged changes, they should be applied to "bar" as well (but not staged).
3. Removing the old file "foo".
Quoted 2 lines
In addition, I don't think giving
--interactive a filename is meaningful...
Whoops. I think I just inadvertently proposed a feature... my most common use of "git-add --interactive" is when I want to stage only specific hunks of a particular file, and so instead of typing "git add bar" I want to type "git add -i bar" and have it jump straight to the "patch" subcommand (5) for that file. Would anyone else find this useful?
Cheers,
Wincent
Quoted 5 lines · Wincent Colaiuta
Whoops. I think I just inadvertently proposed a feature... my most common use of "git-add --interactive" is when I want to stage only specific hunks of a particular file, and so instead of typing "git add bar" I want to type "git add -i bar" and have it jump straight to the "patch" subcommand (5) for that file. Would anyone else find this useful?
Yes, my only use of git-add --interactive is to stage particular patches from individual files. So I would find that feature useful.
-Peff