Docker on Windows permission denied when git stash a file - windows

With the latest version of Docker for Windows.
I got a php git repository that 2 of my containers use.
I modify a random file on the host : README.md
Then I do these git command one after the others :
git stash # ok
git stash pop # ok
git stash # ok
git stash pop # ok
git stash : => Takes 1 minute, then :
error: unable to create file README.md: Permission denied
fatal: Could not reset index file to revision 'HEAD'.
I also noticed that from inside the container :
root#317635dc4f03:watch -n 1 head README.md
Every 1.0s: head README.md
Thu Aug 10 16:27:37 2017
head: cannot open 'README.md' for reading: Stale file handle
Then
head: cannot open 'README.md' for reading: No such file or directory
On the Window host the file is visible but I can't open it neither delete it (permission denied)
I need to stop docker, stop the Hyper-V MobyLinuxVM, and wait to be able to restore the README.md file with a git reset --hard
Is there any way to avoid this kind of file sharing problem ?
Docker 17.06.0-ce |
Windows 10 pro : 15063.540 |
Hyper-V : 10.0.15063.0 |
Moby, trusty,

Related

GitHub Desktop Error: fatal: git show-ref: bad ref refs/tags/desktop.ini [duplicate]

Using git 1.6.4.2, when I tried a git pull I get this error:
error: unable to resolve reference refs/remotes/origin/LT558-optimize-sql: No such file or directory
From git+ssh://remoteserver/~/misk5
! [new branch] LT558-optimize-sql -> origin/LT558-optimize-sql (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/split-css: No such file or directory
! [new branch] split-css -> origin/split-css (unable to update local ref)
I've tried git remote prune origin, but it didn't help.
Try cleaning-up your local repository with:
$ git gc --prune=now
$ git remote prune origin
man git-gc(1):
git-gc - Cleanup unnecessary files and optimize the local repository
git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
(to reduce disk space and increase performance) and removing unreachable objects which may have been
created from prior invocations of git add.
Users are encouraged to run this task on a regular basis within each repository to maintain good disk
space utilization and good operating performance.
man git-remote(1):
git-remote - manage set of tracked repositories
git remote prune [-n | --dry-run] <name>
Deletes all stale remote-tracking branches under <name>. These stale branches have already been
removed from the remote repository referenced by <name>, but are still locally available in
"remotes/<name>".
Happened to me as well. In my case, the bad ref was master, and I did the following:
rm .git/refs/remotes/origin/master
git fetch
This made git restore the ref file. After that everything worked as expected again.
This did the job for me:
git gc --prune=now
For me, it worked to remove the files that are throwing errors from the folder .git/refs/remotes/origin/.
I just would like to add one of the possible causes of a broken Git reference.
Possible root cause
On my system (Windows 7 64-bit), when a BSOD happens, some of the stored reference files (most likely currently opened/being written into when the BSOD happened) are overwritten with NULL characters (ASCII 0).
As others mentioned, to fix it, it's enough to just delete those invalid reference files and re-fetch or re-pull the repository.
Example
Error message:
cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken
Solution:
Delete the reference refs/remotes/origin/some/branch which is stored in the file %repo_root%/.git/refs/remotes/origin/some/branch.
Go to under flutter folder and then,
Try it:
git gc --prune=now
git remote prune origin
git pull
Explanation: It appears your remote repo (in GitHub / BitBucket) branches were removed ,though your local references were not updated and pointing to non existent references.
In order to solve this issue:
git fetch --prune
git fetch --all
git pull
For extra reading - Reference from Git documentation :
git-fetch - Download objects and refs from another repository
--all
Fetch all remotes.
--prune After fetching, remove any remote tracking branches which no longer exist on the remote.
Execute the following commands:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Just in case, if you need to know what is
.git/refs/remotes/origin/master, you would read the Remotes section
in Git References.
In my case, the problem was solved after I've deleted all the remove reference files under the directory .git.
If you look at the message, it would tell you which files you need to delete (specifically).
The files to delete sit under .git/refs/remotes.
I've just deleted all the files there, and ran gc prune
git gc --prune=now
After that, everything works just fine.
git fetch --prune fixed this error for me:
[marc.zych#marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:25]
[I]> git fetch
error: cannot lock ref 'refs/remotes/origin/user/janek/integration/20170505': 'refs/remotes/origin/user/janek/integration' exists; cannot create 'refs/remotes/origin/user/janek/integration/20170505'
From github.com:zooxco/driving
! [new branch] user/janek/integration/20170505 -> origin/user/janek/integration/20170505 (unable to update local ref)
From github.com:zooxco/driving
[marc.zych#marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:30]
[I]> git fetch --prune
- [deleted] (none) -> origin/user/janek/integration
This assumes that the offending branch was deleted on the remote, though.
You can also add this to ~/.gitconfig to automatically prune when running git fetch:
[fetch]
prune = true
I had this same issue and solved it by going to the file it was erroring on:
\repo\.git\refs\remotes\origin\master
This file was full of nulls, I replaced it with the latest ref from github.
If this error “unable to update local ref” is reoccurring, even after applying either the answer by Vojtech Vitek or Michel Krämer you may you may have a bad ref on your local AND master repository.
In this case you should apply both fix's without pulling or pushing in between ...
rm .git/refs/remotes/origin/master
git fetch
git gc --prune=now
git remote prune origin
A permanent resolution for me was only achieved after applying both fix's before push/pull.
For me, I solved it this way:
rm .git/refs/remotes/origin/master
git fetch
After that I get this message from github.
There is no tracking information for the current branch
So next I did to fix this was:
git branch --set-upstream-to=origin/master master
git pull
To Answer this in very short, this issue comes when your local has some information about the remote and someone changes something which makes remote and your changes unsync.
I was getting this issue because someone has deleted remote branch and again created with the same name.
For dealing with such issues, do a pull or fetch from remote.
git remote prune origin
or if you are using any GUI, do a fetch from remote.
Try this:
git pull origin Branch_Name
Branch_Name, the branch which you are currently on.
If you do only a git pull, it pulls all other created branch name as well.
So is the reason you are getting this:
! [new branch] split-css -> origin/split-css (unable to update local ref)
I was able to work with
git remote update --prune
$ rm .git/refs/remotes/origin/master
$ git fetch
From bitbucket.org:xx/mkyong-tutorials
df0eee8..3f7af90 master -> origin/master
$ git pull
Already up to date.
Error: cannot lock ref" simply means information in /refs are corrupted and Git cannot continue to create index.lock file.
Quick fix : Remove and re-add remote.
1- Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:
git remote -v
2- Remove the remote from your local git repo:
git remote rm origin
3- Add the remote back to your local repo:
git remote add origin git#server-address.org:your-username/repo-name.git
4- Prune remote origin
Users across online forums have reported that the command below worked for them:
git remote prune origin
5- Clean up and optimize local repository
git gc --prune=now
You can find more info on this article:
https://linuxpip.org/git-error-cannot-lock-ref/
delete file for particular branch manually from your project
.git/refs/remotes/origin/master
git gc --prune=now
git pull
For me, I had a local branch named feature/phase2 and the remote branch was named feature/phase2/data-model. The naming conflict was the cause of the problem, so I deleted my local branch (you could rename it if it had anything you needed to keep)
If git gc --prune=now dosen't help you. (bad luck like me)
What I did is remove the project in local, and re clone the whole project again.
I'm using Tower and for some reason my folder name was .git/refs/remotes/origin/Github. Changing it to lowercase .git/refs/remotes/origin/github solved the issue.
When it is caused by Google Drive desktop.ini files
Google Drive client for Windows creates desktop.ini files in each folder. If your git repository is in a directory that is being synced with Google Drive, then the desktop.ini files will cause the git repository to fail with something like:
cannot lock ref 'refs/remotes/origin/desktop.ini': unable to resolve reference 'refs/remotes/origin/desktop.ini': reference broken
To solve this error you might want to delete the desktop.ini files in your git repository.
If you have WSL setup, then you can use the following command to delete the desktop.ini files:
Note: ⚠️ This command will delete all desktop.ini files in all .git directories in your <project_directory>.
find <project_directory> -type d -name .git -print0 | xargs -0 -I {} find {} -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}
If you just want to delete the desktop.ini files in a specific .git directory, then you can use the following command:
find <.git_directory> -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}
Tried these but didn't work for me:
$ git gc --prune=now
$ git remote prune origin
$ git fetch --prune
I had to get this fixed by deleting the local folder and cloning again.
I had same issue. i follow following steps
1)switch your branch which having issue to other branch
2) delete that branch
3) checkout again.
Note:- You can stash you uncommitted changes and put it back again.
Got this issue when trying to clone from a git bundle created file, none of the other answers worked because I couldn't clone the repo (so git gc and removing/editing files was out of the question).
There was however another way to fix this - the source file of a .bundle file was begining with:
# v2 git bundle
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d HEAD
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
PACK.......p..x...Kj.0...: (and so on...)
Simply removing the fourth line with vim fixed the issue.
I used git prune origin and that did the work.
Writing down a specific case that might cause this problem.
One day I pushed a branch named "feature/subfeature", while having "feature" branch on remote.
That operation worked fine without any error on my side, but when my co-workers fetched and/or pulled any branch, they all had the exact same error message unable to update local ref, cannot lock ref 'refs/remotes/origin/feature/subfeature.
This was solved by deleting feature branch on remote(git push --delete origin feature) and then running git remote prune origin on my co-workers' repo, which generated messages including * [pruned] origin/feature.
So, my guess is git fetch was trying to create subfeature ref in feature folder on git internally(.git/...), but creating folder failed because there was feature ref already.
Try this: git branch --unset-upstream
I was facing the problem earlier but I just solved it when I saw this command on the terminal.
# remove the reference file of the branch "lost"
rm -fv ./.git/refs/remotes/origin/feature/v1.6.9-api-token-bot-reader
# git clear everything
clear ; git reset HEAD --hard ; git clean -xdf ;
# subdue the current branch and pull all changes from the remote
clear ; git fetch --all -p ; git pull --all --rebase ; clear ; git branch -a
# git will "know" how-to handle the issue from now on
# From github.com:futurice/senzoit-www-server
# * [new branch] feature/v1.6.9-api-token-bot-reader ->
# origin/feature/v1.6.9-api-token-bot-reader
# and push your local changes
git push

Pods folder not showing under Git tracking

I am trying to add one of my folder called as Pods - Its for iOS and not showing under Git tracking
I have used below command to check
Git status
To check the current tracking status but not getting help
I have checked the current tracking files by using the command
git ls-tree --full-tree -r HEAD
And the folder getting list as "Pods"
But It's not getting the push on the branch and not showing in git status
I have also tried to check /info/exclude file but this is already blank so no chance to ignore
After applying git log --stat -- Pods
It shows me like
Pods | 1 +
1 file changed, 1 insertion(+)
git status will only show changed or untracked files. Your Pods directory is probably already committed and therefore tracked.
Try git log --stat -- Pods.

"Not a git repository" after OS reset

This morning my Windows 10 crashed and rebooted once I lifted my laptop's screen. No special activity was progressing, so I don't think there was significant disk activity.
However one of my main Git repos crashed after that reset. Here is what I tried:
$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ git init
Reinitialized existing Git repository in ....../.git/
$ git status
fatal: Not a git repository (or any of the parent directories): .git
Loop
I don't think I have unpushed commits, so wiping and cloning from remote should work.
Still, can I ask what to do to recover an existing Git repository (.git directory still exists, chkdsk reports OK) in such cases?
[Add] read this but did not apply to my case (I can't restore the repo)
As kabanus said in a comment, you should definitely save whatever you can before proceeding (and/or use some other existing clone as a backup).
When Git complains about this, though, it often means that the file .git/HEAD has gone missing. If you create a new HEAD file with contents: ref: refs/heads/master, Git may be able to recover everything.
Since HEAD is the most active file in the repository, it's the one most likely to be clobbered by an OS error or power failure. It's also a critical file when it comes to whether Git believes a .git directory is a repository: if the directory contains a file named HEAD (along with a few other key items), it is a repository; if not, it is not a repository.
I had multiple branches corrupt due to OS error (bloody windows sleep function!!). So I had to manually do the following:
.git/HEAD (set content to ref: refs/heads/master)
$> git branch -v (this will tell you all the corrupt branches)
.git/logs/HEAD (Read the file for last checksum of the commits and merge of corrupt branches)
.git/refs/heads/{corrupt branch file} (change the checksum to the last working checksum from the log file.
merge the branches again as per need.
Another workaround for this, Solved for me while OS crashed on GIT MERGE operation
Get the working HEAD,FETCH_HEAD files under .git/ directory(of your project) from some other contributor
Replace the existing HEAD,FETCH_HEAD files with new ones(taken from other contributor).
Delete the INDEX under .git/ directory.
Then Do a git pull.
In my case, the HEAD file was indeed corrupted due to a system crash.
I just cloned the repo again into a new folder, switched to the branch I was in, then replaced the .git folder with the one I just created from the clone.
From there, it was like nothing happened.
In my case, The ownership of the repo was mismatched after OS reset.
I tried #raheel-hasan's instructions, after entering git branch -v command I got a suggestion.
git config --global --add safe.directory 'direactory path' this command solved the issue :)
(Use powershell to run this command)
You shoult reload your IDE or code editor after running this command.

git plugin on windows command fails from Jenkins, succeeds in shell [duplicate]

This question already has answers here:
Unable to get Jenkins and Git to play nice
(2 answers)
Closed 7 years ago.
I'm setting up Jenkins on my windows build machine, with the Git Plugin. I'm using a directory on a network drive Z: as the git repository for now. I enter "z:\my\repo\path" for the Repository URL, and I get:
Failed to connect to repository : Command "git.exe -c core.askpass=true ls-remote -h z:\my\repo\path HEAD" returned status code 128:
stdout:
stderr: fatal: 'z:\my\repo\path' does not appear to be a git repository
fatal: Could not read from remote repository.
Yet if I open a fresh command prompt and type that command, it works without error (and also no output):
> git.exe -c core.askpass=true ls-remote -h z:\my\repo\path HEAD
>
What may possibly be the issue? I am not even sure where to begin. I've set the PATH and GIT_HOME system environment variables and restarted Jenkins, so clearly it is finding the executable.
I've tried the file:///-style path and had the same results.
Output of the manual command with GIT_CURL_VERBOSE=1 and GIT_TRACE=1 set:
15:43:24.905801 git.c:348 trace: built-in: git 'ls-remote' '-h' 'z:\\my\\repo\\path' 'HEAD'
15:43:24.905801 run-command.c:343 trace: run_command: 'git-upload-pack '\''z:\\my\\repo\\path'\'''
I believe the problem could be around correctly setting up the SSH keys.
First suggestion - UNC path for the repo
Can you try using the file://// format for the repo instead of windows path?
If it's a share try using git clone file:////<host>/<share>/<path> instead.
Please use this as reference.
Second suggestion - SSH Keys
From https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin- :
(though the error is different that what you have)
Some windows fun
If you did everything, you should now have a ~/.ssh folder
(c:\Users\Bob.ssh for instance) and this folder contains your keys.
At that point, you may even be able to manually (from the console),
clone your repository but Jenkins keeps failing with something like
this:
code 128: Cloning into C:\Program Files\Jenkins\jobs\PG3\workspace...
fatal:
The remote end hung up unexpectedly
If you run into this issue, you may need to copy the id_rsa* files
from your ~./.ssh to another folder. Find your git.exe and check if
there is an .ssh folder there. If so, copy ~./ssh/id_rsa* to this
folder and try again.

Git on windows - cannot push to remote repository using the local (file) protocol

I am using Git version 1.9.2-preview20140411 on Windows 7 Enterprise SP1 x64.
When I try to push to a remote repository using the local (file) protocol, I get the error:
fatal: 'orgin' does not appear to be a git repository
fatal: Could not read from remote repository.
Here are the steps to reproduce:
$ cat PushTestCase.sh
#!/bin/bash
set -o xtrace
cd /C/work/Git
git init --bare MyProjectBare
git clone MyProjectBare MyProjectClone
cd MyProjectClone
echo "apples, oranges" > fruit.txt
git add fruit.txt
git commit -a -m "First commit"
git push orgin master
git remote -v
git remote show orgin
$ PushTestCase.sh
+ cd /C/work/Git
+ git init --bare MyProjectBare
Initialized empty Git repository in c:/work/Git/MyProjectBare/
+ git clone MyProjectBare MyProjectClone
Cloning into 'MyProjectClone'...
warning: You appear to have cloned an empty repository.
done.
+ cd MyProjectClone
+ echo 'apples, oranges'
+ git add fruit.txt
warning: LF will be replaced by CRLF in fruit.txt.
The file will have its original line endings in your working directory.
+ git commit -a -m 'First commit'
warning: LF will be replaced by CRLF in fruit.txt.
The file will have its original line endings in your working directory.
[master (root-commit) 74ee22d] First commit
warning: LF will be replaced by CRLF in fruit.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+)
create mode 100644 fruit.txt
+ git push orgin master
fatal: 'orgin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
+ git remote -v
origin c:/work/Git/MyProjectBare (fetch)
origin c:/work/Git/MyProjectBare (push)
+ git remote show orgin
fatal: 'orgin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$
Originally I tried this with the remote repository on a network drive. In order to eliminate any possible permission issues, I've reproduced the problem using a remote repository on a local drive.
I know another option is to setup SSH on the server, but I would much rather get this working using the local protocol.
Your script has a typo. Correct:
git push orgin master
to:
git push origin master

Resources