Why does git sparse checkout leave behind directories? - windows

Some background: My company's service model began as an appliance-based server model. We would send our client a server with Windows Server 2003/2008 on it, pre-loaded with a webserver and our software. We're moving all of the client-specific configuration to a Git repository, and using sparse-checkout to make each server only contain what's necessary for the client's software to function properly.
While setting up sparse-checkout, we've run into a huge inconsistency. We'll do
git clone git#github.com:ourclientconfigrepo.git .
git config core.sparsecheckout true
echo www.thisclient.com/ > .git/info/sparse-checkout
git read-tree -m -u HEAD
The expected result would be
ls
www.thisclient.com/
but we get
ls
www.thisclient.com/
www.randomclient1.com/
www.randomclient2.com/
www.randomclient3.com/
I've tried multiple times, in a new directory each time, and the issue has happened each time. My ju-git-su fails me here. We're using git version 1.8.1.msysgit.1.
Thanks for your help, let me know if I need to supply more information.
---EDIT 1---
Clarification: The repository is nothing but our client's configuration directories. Each client has a different directory in the repository, and we're trying to sparse-checkout on each client's individual server, so we're trying to exclude everything except for the client in question.
---EDIT 2---
Just an update, turns out it was something wonky with Windows folder permissions, and Git was trying to delete non-empty directories. Fixed it by deleting the empty folders. Thanks for any and all attempts at helping!

Your clone operation is not the correct way to create a sparse clone. Instead of:
git clone ...
You should use this sequence:
mkdir repo ; cd repo ; git init
git remote add -f origin <url>
git config core.sparsecheckout true
echo <dir1>/ >> .git/info/sparse-checkout
echo <dir2>/ >> .git/info/sparse-checkout
echo <dir3>/ >> .git/info/sparse-checkout
git pull origin master

A partial solution: According to git-read-tree(1), you can exclude specific files by putting a ! in front of the file name. This may be a miswrite, however (meaning that that's for directories as well, not files).
I'll continue investigating.
According to https://stackoverflow.com/a/11222033/1210278, you can manually mark directories with git update-index --skip-worktree www.randomclient1.com/.
https://stackoverflow.com/a/9575837/1210278 implies that exclusion is only for directories, and says that there are some bugs with it.

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

Cannot git checkout master: invalid path '?'

After an "unsuccessful" git pull on my local master, an error prevents to switch back to master:
C: repo_folder> git checkout master
error: invalid path '?'
The ? must be because it is a keybase repo.
From another branch where I checked out some files of the last commit:
C: repo_folder> git diff origin/master --compact-summary
"\004" (gone) | 1902 ---------------------------
some irrelevant stuff | (num) -
The removed file "\004" (that was never present in my local) seems to come from some Mac OS (someone might have opened a csv and a temporary file was created when that user did the commit and pushed?).
observe that the file that is marked as (gone) is to be removed by git
the problem is that the filename has characters that are not compatible with the Windows file system and that the file never existed in my local Windows repo.
If I clone from a Linux platform, I can checkout to master with no problems. However, in Windows, there's no way back to the master branch.
Any ideas on how to solve this issue? (already tried some posts with no success)
I can't really understand how it comes git doesn't even allow me to checkout to master. Should I file a bug report?
Alternatively, perhaps I could create a new master branch and get rid of the current one.
EDIT
A clone from Linux helped to identify that the file ? was actually there.
This could be checked directly from Windows as well by using the command: git ls-tree origin/master (which was showing the original problematic name "\004")
The accepted answer includes the case where you want to save the content of the file, while in my case I only wanted to get rid of it. So in my case, I have just deleted the file from Linux, committed and pushed the change, and did a git fetch origin master:master to fetch my local master with being checked out in another branch (as I was not able to checkout to master). This finally did the trick and I could checkout to master.
Hope this clarifies to someone with a similar problem.
? (or maybe it's EOT) cannot be used as a filename on Windows. The file will have to be deleted or renamed. You can do this most easily by cloning on a system which does allow ? and making the fix.
If you only have Windows, Fixing Invalid Git Paths on Windows offers a method of renaming the file without checking it out. In brief...
git checkout origin/master -f to get the checkout without the problematic file.
Make a branch.
Add and commit the "deleted" problematic file.
Use git ls-tree HEAD^ to get the ID of the problem file.
Use git cat-file -p <ID> to get the content of the problem file.
Put the content into a new file.
Add and commit.

something went wrong when pushing to github with webstorm

As is shown in the image,I'm not sure if the failure is caused by some missing property while setting up webstorm .
The issue is not resolved after a lot of efforts.As a learner,I don't know what to do now.
Meanwhile,something seems wrong as shown in git bash.I've no idea whether the two are directly related.
If you have ever faced these difficulties,could you please give me some idea? Even if it's only a web address.
What I want to do is only pushing my code. Anyone who pushed successfully in any other way will be welcomed to share your method.
If I'm being honest I'm not sure that I completely understand your question, but I will supply some information that will hopefully lead you down the right track.
First in the bash shell, cd (change directory) into your project directory like this:
$ cd /c/foo/bar/yourprojectfolder
In your project top most directory, do you have a .git folder? You may have to show hidden folders in windows to see this directory. If not, you need to initialize a repository with the init command.
$ git init
Initialized empty Git repository in C:/foo/bar/yourprojectfolder/.git/
After running this command, you should see a .git folder inside of the directory you changed to (used cd to get to) earlier.
Next, in order to push, you first need a remote repository to push to. Based on your first picture, I believe that you have successfully created a repository on GitHub. If not however, just log into GitHub and click the 'New Repository' button:
Once a repo has been created, you need to add it as a remote to your local git (in git bash). To do this you need a url (either SSH or HTTPS) to your repo. You can find this url inside of your repository in online GitHub. If you are not certain you have set up SSH, it's best to use the HTTPS url. It should look something like this, but the url itself will be different and specific to your repository:
Copy that url to your clipboard, and then back in git bash run:
$ git remote add origin <PASTE YOUR URL HERE>
You need to make an initial commit of your code to have something to push:
$ git add .
$ git commit -m "Initial commit"
Finally, with the origin repo set up and a commit made, you should be able to push to your origin repo
$ git push -u origin master
You should now be able to view your code on GitHub.

error: Sparse checkout leaves no entry on working directory

First, let me tell you that I have already checked all the similar threads and searched google to find what the problem may be, but no success. My problem is that I'm trying to use sparse checkout in git, but I get this error:
error: Sparse checkout leaves no entry on working directory
I have this 60GB repository, which I need to clone. I need only a part of it, so to save a disk space I wanted to use sparse checkout. This is what I do:
mkdir repoDir
git init repoDir
cd repoDir
git remote add origin <repo url>
git config core.sparsecheckout true
echo "some/dir/" >> .git/info/sparse-checkout
git pull --depth=1 origin master
Note I add the remote without -f flag, so nothing is fetched.
The result:
error: Sparse checkout leaves no entry on working directory
I tried several things:
Instead of initialising new repo and adding the remote manually, I did git clone --no-checkout and then set up the sparse checkout. This didn't help as my git status showed as if I deleted all the files in my repo. The git pull origin master command results in the same error.
Tried all possible combination of paths in step 6, with preceding slashes, slashes after the path, stars, spaces between path and > or >>. Btw I'm confused what is the correct format here, from the comments on SO I see mutually exclusive ways of formatting this.
Tried to make sure my .git/info/sparse-checkout is ASCII, and has proper line endings as found here. This is probably only problematic on Windows, but I just checked this anyway.
My git version: git version 1.9.3 (Apple Git-50)
OSX Yosemite 10.10.2 (14C109)
It turns out that "some/dir/" was wrong, since I didn't have the repository I didn't know it's real structure. I was able to browse it through web interface but I just discovered the folders don't correspond exactly to the real repository folder structure.
Lesson for the future: make sure you know the folder structure before creating sparse-checkout file.
The sequence of operations I wanted to follow is similar, namely the one suggested in this other post https://stackoverflow.com/a/13738951/5459638. I get the error message
error: Sparse checkout leaves no entry on working directory
when launching git pull <remote> <branch> with branch being master.
As #lawicko said, in the project webpage I can click my way to the subdirectory to be cloned and copy the URL of that page; ctrl+L ctrl+C makes doing this nice and quick. This URL has the form
https://gitlab.com/<username>/<project>/tree/master/<subdir>/<subdir>
The part that my sparse-checkout file accepts is the children of master
<subdir>/<subdir>/
with the trailing slash.
As an alternative to the same aim, there is another path in the form <project>/<subdir>/<subdir> to the right of the drop-down menu for switching branches at the top of the webpage.
In this case, I would have copied and pasted the children of <project> plus the trailing slash.
And this path is not as easy to copy and paste as the URL is.
Note that if you are using sparse-checkout on windows, you may need to add core.protectNTFS false per https://github.com/git-for-windows/git/issues/2777

How to pull and check-out remote Git repository

OK, total noob question, for msysgit on Windows 7, but I have a remote repository (on unfuddle), create on one PC, and now I want to pull it down to another PC. I tried 'Fetch' using Git Gui, but the folder still only has a .git subfolder. It took a while pulling it down, so I assume there is something in the repo, but how do I check it out to a working copy. Nothing I have tried seems to work.
SOLUTION:
It's not directly in his answer, but VonC below pointed me to the unfuddle help documentation for Git, which is as terse as the Git man-pages are dense. The follwing single command got me the working copy and local repository I needed:
$ git clone git#subdomain.unfuddle.com:subdomain/abbreviation.git
Following the Git documentation on Unfuddle, did you declare your unfunddle repo as a remote?
$ cd /path/to/repository
$ git remote add unfuddle git#subdomain.unfuddle.com:subdomain/abbreviation.git
Try also gitk --all: if the fetch has succeded, you should the remote tracking branches (like unfuddle/master). You can then merge it to your master branch in order to finally see files in your (still empty) working tree.
You could also have done a git pull to combine the two steps together (fetch+merge). See this blog post for illustration.
Actually, the OP ProfK reports a cloning issue:
I did already have the unfuddle remote added
git clone git#subdomain.unfuddle.com:subdomain/abbreviation.git
is more suited to get a local repo with the right remote already added to it.

Resources