New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad revision for stash #589

Closed
roblourens opened this Issue Dec 11, 2018 · 21 comments

Comments

Projects
None yet
3 participants
@roblourens
Copy link

roblourens commented Dec 11, 2018

The error from #588...

  • I open the gitlens sidebar
  • Right click any stash, click "apply"
  • The stash can't be applied, and the output channel says something like Error: fatal: bad revision 'stash@{0}^3'

Seems that the @{} syntax can't be combined with ^?

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 11, 2018

@roblourens are you attempting to apply the whole stash or just a single file from it?

@roblourens

This comment has been minimized.

Copy link

roblourens commented Dec 11, 2018

The whole stash

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 11, 2018

@roblourens can you try gitlens-9.0.4-beta.vsix.zip and see if it resolves the issue?

@roblourens

This comment has been minimized.

Copy link

roblourens commented Dec 11, 2018

No, same issue.

I get the error just from clicking on the stash, not trying to apply it necessarily.

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 11, 2018

Hrm, I can't seem to reproduce that. Can you set the outputLevel to debug and send me logs?

@roblourens

This comment has been minimized.

Copy link

roblourens commented Dec 11, 2018

I set the outputLevel to debug, cleared the output channel and clicked around a bit. Not sure there's any more detail. Is there a different log?

[2018-12-11 16:58:27:826] [db] GitService.getLog — e=/Users/roblou/code/vscode, t={"maxCount":1,"ref":"stash@{4}^3"}
[2018-12-11 16:58:27:843] git — -c, core.quotepath=false, -c, color.ui=false, -c, diff.renameLimit=0, log, --name-status, --format=%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e, --full-history, -M, -m, -n1, stash@{4}^3, --,   cwd='/Users/roblou/code/vscode'

  
Error: fatal: bad revision 'stash@{4}^3'

[2018-12-11 16:58:27:844] [/Users/roblou/code/vscode] git log --name-status --format=%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e --full-history -M -m -n1 stash@{4}^3 -- • 17 ms 
[2018-12-11 16:58:27:844] [db] GitService.getLog completed • 17 ms
[2018-12-11 16:58:31:231] [dc] GitService.getLog — e=/Users/roblou/code/vscode, t={"maxCount":1,"ref":"stash@{5}^3"}
[2018-12-11 16:58:31:256] git — -c, core.quotepath=false, -c, color.ui=false, -c, diff.renameLimit=0, log, --name-status, --format=%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e, --full-history, -M, -m, -n1, stash@{5}^3, --,   cwd='/Users/roblou/code/vscode'

  
Error: fatal: bad revision 'stash@{5}^3'

[2018-12-11 16:58:31:257] [/Users/roblou/code/vscode] git log --name-status --format=%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e --full-history -M -m -n1 stash@{5}^3 -- • 25 ms 
[2018-12-11 16:58:31:257] [dc] GitService.getLog completed • 25 ms
[2018-12-11 16:58:35:767] [dd] GitService.getLog — e=/Users/roblou/code/vscode, t={"maxCount":1,"ref":"stash@{6}^3"}
[2018-12-11 16:58:35:786] git — -c, core.quotepath=false, -c, color.ui=false, -c, diff.renameLimit=0, log, --name-status, --format=%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e, --full-history, -M, -m, -n1, stash@{6}^3, --,   cwd='/Users/roblou/code/vscode'

  
Error: fatal: bad revision 'stash@{6}^3'

[2018-12-11 16:58:35:786] [/Users/roblou/code/vscode] git log --name-status --format=%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e --full-history -M -m -n1 stash@{6}^3 -- • 19 ms 
[2018-12-11 16:58:35:786] [dd] GitService.getLog completed • 19 ms
@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 12, 2018

Hrm, I can't repro this at all. I see the same git calls, but stash@{0}^3 is a valid ref -- its getting the first stashed and looking for any untracked files in it (see: https://stackoverflow.com/questions/12681529/)

What version of Git do you have? Is this on macOS?

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 12, 2018

I'm assuming if you run the same command on the command line it fails as well?
git -c core.quotepath=false -c color.ui=false -c diff.renameLimit=0 log --name-status --format="%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e" --full-history -M -m -n1 stash@{6}^3 --

Does running git ls-tree -r stash@{0}^3 work?

@roblourens

This comment has been minimized.

Copy link

roblourens commented Dec 12, 2018

I see the same error for that command.

$ git --version
git version 2.17.2 (Apple Git-113)
$ git ls-tree -r stash@{0}^3
fatal: Not a valid object name stash@{0}^3
@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 12, 2018

If you explicitly stash an untracked file and then run those commands against that stash does it work?

@roblourens

This comment has been minimized.

Copy link

roblourens commented Dec 12, 2018

Can you tell me what commands to run? I'm not even clear what the ^3 means here.

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 12, 2018

Add a new file to your repo (but don't stage it), and then right-click on it and select Stash Changes -- GitLens will stash that untracked file.

Then run:
git -c core.quotepath=false -c color.ui=false -c diff.renameLimit=0 log --name-status --format="%x3c%x2ff%x3e%n%x3cr%x3e%x20%H%n%x3ca%x3e%x20%aN%n%x3ce%x3e%x20%aE%n%x3cd%x3e%x20%at%n%x3cc%x3e%x20%ct%n%x3cp%x3e%x20%P%n%x3cs%x3e%n%B%n%x3c%x2fs%x3e%n%x3cf%x3e" --full-history -M -m -n1 stash@{0}^3 --

and

git ls-tree -r stash@{0}^3

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 12, 2018

The way git stores stashes is kind of a 3-way merge (it has 3 parents) -- if you don't have any untracked files (or don't use the --include-untracked) the 3rd parent is just the root of the repo (empty), but if you do include untracked then the 3rd parent is the blob with the untracked file (or at least that's how I understand it)

And the ^ syntax is to get the parent of that ref -- and ^n is to get the nth parent

@roblourens

This comment has been minimized.

Copy link

roblourens commented Dec 12, 2018

$ git ls-tree -r stash@{0}^3
100644 blob 45b983be36b73c0788dc9cbcb76cbb80fc7bb057    test.txt
$ git ls-tree -r stash@{1}^3 # some other stash
fatal: Not a valid object name stash@{1}^3
@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 12, 2018

@roblourens Interesting -- thanks for the info. So it seems that for your "version" of git it fails if there is no 3rd parent (i.e. no untracked files in the stash), but in my version of git it just returns no data.

I'll just put a trap in for this case and treat it as a no data event.

@eamodio eamodio added bug and removed needs more info labels Dec 13, 2018

@eamodio eamodio added this to the Soon™ milestone Dec 13, 2018

@eamodio eamodio self-assigned this Dec 13, 2018

@eamodio eamodio closed this in b1a5a53 Dec 13, 2018

@IoTFier

This comment has been minimized.

Copy link

IoTFier commented Dec 16, 2018

Hi @eamodio - can you please reopen this issue ?
I am using VS Code Version: 1.30.0 (system setup) |
Commit: c6e592b2b5770e40a98cb9c2715a8ef89aec3d74
Date: 2018-12-11T22:29:11.253Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
OS: Windows_NT x64 10.0.17763
Git version 2.20.0.windows.1;
Git Lens version 9.2.0GitLens version 9.2.0

Please help me recover my updates...

Apply Stashed changes command fires up .. git — -c, core.quotepath=false, -c, color.ui=false, stash, apply, stash@{0}, cwd='~ working directory … '
resulting in the error "error: could not restore untracked files from stash" and then for StashApplyCommand fails with another error of same kind. I have few untracked and modified files in the stash....

I am stuck with my stashed changes with the following error …

error: could not restore untracked files from stash
The stash entry is kept in case you need it again.

I am stuck with the risk of many of my changes lost.

@IoTFier

This comment has been minimized.

Copy link

IoTFier commented Dec 16, 2018

@eamodio - while trying to apply those stashed changes .. one of the files popup under repositories window under my local branch. When tried to commit changes from that file it failed... Now I see two lists when I run "git stash list " it shows two lists but nothing under stashes

C:~path~ >git stash list
stash@{0}: WIP on {my branch name}: {commit id} adding 38 files changes stashed from visual code GitLens
stash@{1}: On {my branch name}: Stashing changes related initial code based to {my branch name} per Task # 1
Please help....

This is very discouraging to use GitLens in VSCode...

@IoTFier

This comment has been minimized.

Copy link

IoTFier commented Dec 16, 2018

@eamodio I am not sure if having the same repo open in VSCode and VS simultaneously created any conflicts. But now, under Stashes I see two stashes … When tried to apply on of the stashes will multiple files that was giving me above error .. I observed an exclamation mark shown in the notification window as pointed below. Am I missing setting up any configuration of the GitLens Extn ? Is there a command that I need to run to push these stashed files on my branch ?

I am just wondering if I should have just staged my changes instead of stashing ….

image

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 16, 2018

As long as you don't delete the stash (or delete after applying) you run no risk of losing your changes -- they are safely contain within the stash.

While I'm not sure of what is really going on here, but my guess is that the stash couldn't be applied cleanly to the working directory because there were conflicts -- e.g. a file that was not tracked in the stash that exists in the working directory, or there is a file with uncommitted changes in the working directory that the stash will affect.

Your best bet is to make sure you have a clean working directory (no uncommitted or untracked files) and then try to apply the stash.

FYI, staging and stashing are VERY different things -- staging is what happens when you call git add it adds the file to the index (staging area) to be committed. While stashing is to take a set of changes and "stash" them (save them off and reset the working directory) to come back to later.

@eamodio

This comment has been minimized.

Copy link
Owner

eamodio commented Dec 16, 2018

FYI all GitLens is doing to apply that stash is (assuming you are apply in the first stash)

git stash apply "stash@{0}"

Which you can run directly and git should list what files are in conflict

@IoTFier

This comment has been minimized.

Copy link

IoTFier commented Dec 16, 2018

running git stash apply "stash@{0}" throws following message and an error
C:{path}>git stash apply "stash@{0}"
On branch {branch name}
Your branch is ahead of 'origin/{branch name}' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean

image

Running that command on "stash{1}" still throws the same error "error: could not restore untracked files from stash" and for some files it says {file name with path } already exists, no checkout ..

After I run those git commands, nothing is shown under the Stashes but running git stash list command shows two stashes stash{0} and stash{1}..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment