I have a big (more than 1000 files) VS C# project in git. I need to create a small demo project and use ten files from the big project. To create this new project, I added ten files with mklink (symlink) from the big project to the small. All changes in corresponding files in the big and small project are identical. Now I need to add the small project to a different (my own) git repo.
But symlink will not add in git :
(error: readlink("X.cs"): Function not implemented)
How to add the X.cs (symlink) file in git as a regular file?
I need all changes in X.cs (in big project) to be moved to X.cs (small project).
If adding symlinks to the index fails with error error: readlink("..."): Function not implemented, try to find this line in the local or global config:
[core]
symlinks = false
You need to set symlinks = true for a successful push. Default value (=true) if parameter does not exist or is not working correctly and it depends on the settings with which the repository was created.
Hardlinks do not work with GIT, as the file and hardlink are stored as separate files.
It works the same with git version 2.8 or above (I did not check versions less than 2.8)
The current answer(s) are out-of-date and require revision given recent changes.
The solutions given there isn't enough and isn't working.
There are still issues with the latest Git 2.12 on Windows (February 2017, 18 months after the OP's question)
In the context of working on what was called git-new-workdir in 2015 (the ability, form one clone, to have multiple working tree: this ended up being called git worktree), the Git developers were asking how to reference those worktrees from the main cloned repo.
Would they be using ln? or its Windows equivalent mklink?
This thread, at the time, highlighted the issues:
When running on Windows in MinGW, creating symbolic links via ln always failed.
Using mklink instead of ln is the recommended method of creating links on Windows
That might be true, but not ideal: "Git Bash Shell fails to create symbolic links" does mention:
For my setup, that is Git for Windows 2.11.0 installed on Windows 8.1 export MSYS=winsymlinks:nativestrict does the trick as explained here: git-for-windows/pull/156
It's important to launch the Git Bash shell as administrator as on Windows only administrators could create the symbolic links. So, in order to make tar -xf work and create the required symlinks:
Run Git Bash shell as an administrator
Run export MSYS=winsymlinks:nativestrict
Run tar
See also "Git Symlinks in Windows", where the setup now (Git for Windows 2.10+) include symlink support:
You need to specify that during the clone:
git clone -c core.symlinks=true <URL>
And your CMD session needs to be run as admin.
Needless to say imposing that prerequisite on Windows users is a no-go (Windows in enterprise generally come with limited or no privilege elevation)
Yet, PR 156 does represent some Windows support for symlink, released in Git For Windows 2.10 (Sept. 2016).
It is telling that git worktree ended up implementing the multiple working tree reference... by not relying on symbolic links and by making the borrowee and borrowers aware of each other.
When you are done with a linked working tree you can simply delete it.
The working tree's administrative files in the repository will eventually be removed automatically (see gc.pruneworktreesexpire in git config), or you can run git worktree prune in the main or any linked working tree to clean up any stale administrative files.
So no symbolic link there.
git has problems with individual file links but it has no problem with directory symbolic links(mklink /d ). Therefore move your image files to another directory in your big project and create directory link in your git repo to this directory.
See below for example.
P:\denemeler\gitdeneme1>mklink /d linkDirectory P:\puzzles
Created symbolic link : linkDirectory <<===>> P:\puzzles
P:\denemeler\gitdeneme1>git status
On branch master Untracked files:
(use "git add ..." to include in what will be committed)
linkDirectory/
nothing added to commit but untracked files present (use "git add" to
track)
P:\denemeler\gitdeneme1>git add linkDirectory
P:\denemeler\gitdeneme1>git status
On branch master Changes to be
committed: (use "git reset HEAD ..." to unstage)
new file: linkDirectory/Juggle Fest Question.txt
new file: linkDirectory/jugglefest.txt
new file: linkDirectory/triangle.txt
new file: linkDirectory/triangleQuestion.txt
P:\denemeler\gitdeneme1>git commit -m "new files"
[master 0c7d126] new
files 4 files changed, 14150 insertions(+) create mode 100644
linkDirectory/Juggle Fest Question.txt create mode 100644
linkDirectory/jugglefest.txt create mode 100644
linkDirectory/triangle.txt create mode 100644
linkDirectory/triangleQuestion.txt
P:\denemeler\gitdeneme1>echo "aa" > p:\puzzles\newFile.txt
P:\denemeler\gitdeneme1>git status
On branch master Untracked files:
(use "git add ..." to include in what will be committed)
linkDirectory/newFile.txt
nothing added to commit but untracked files present (use "git add" to
track)
Git does indeed have trouble with symlinks on Windows. However, I don't think you even need symlinks for your problem. A simple workaround is to write a small *.bat script to copy the files in question from one repository to another on demand. With symlink, you don't need to run a script, which saves you a few seconds, but you get a problem that you can accidentally change file in small repository and have unwanted modification in big repository.
Looks like all your simlinks located in one ntfs partition, if it is true, you can renew all simlinks to hardlinks, by some script with command, mklink /h...
Hardlinks friendly for any CVS.
Related
Using the command line or a third-party git manager, I can execute basic git commands like commit, reset and stash with MATLAB open, presumably because I'm working solely on my local branch. As soon as I want to use git checkout somebranch I get the error:
fatal: cannot create directory at [dir]: Permission denied
What's worse is that my current working directory (on the old branch) now has unstaged changes from the branch I wanted to checkout. Other programs simply reload the files from the newly checked out branch. I've tried finding a way to change how MATLAB locks files but to no avail.
MATLAB R2017b
Windows 10 Pro
More Info
The file structure in my git directory is different between the two branches. I think the issue arises from the fact that a deleted sub-directory was in MATLAB's "set path" list.
First, I would recommend
using a separate git (from the latest Git for Windows and a simplified path)
using a separate working tree (meaning a separate folder) with git worktree.
Second, double-check any locking issue with Process Explorer.
This question already has answers here:
Remove a file with a strange name from git
(3 answers)
Closed 7 years ago.
TL;DR summary
Weird files appeared. They show on git but not on disk. A list of possible programs causing that are listed.
Why did they appear?
How can I get rid of them now?
There is a weird \200 character I cannot type.
For the record: the solution that worked for me is the second answer of user VonC: https://stackoverflow.com/a/13250936/1255826
I already had to copy all the files and make a new Git repository, removing the .git folder from my project to try and fix this. git status claims there are modified files/folders with a very strange \200 character in their name, when actually I didn't add those.
To clarify, I cannot see any file with those names on my disk. I can only assume there is something weird going on in the .git folder. I've tried to see if there are any hidden files with that \200 part in their name. There aren't. (I even have the "show hidden files and folders" option enabled on my computer):
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$ ls
es3.c student
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$ ls -ahf
. .. es3.c student
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016/laboratorio/lab5/es3/src
$
See my terminal log here to see exactly what I mean.
Note that git status didn't show these files, that were added a second later when I used the git add -A command. Then, after that, these "ghost" files are shown:
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git status
Sul branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: laboratorio/lab5/es3/Makefile
modified: laboratorio/lab5/es3/src/es3.c
modified: laboratorio/lab5/es3/src/student/student.c
modified: laboratorio/lab5/es3/src/student/student.h
Untracked files:
(use "git add <file>..." to include in what will be committed)
laboratorio/lab5/es3/.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git add -A
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$ git status
Sul branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: laboratorio/lab5/es3/.gitignore
modified: laboratorio/lab5/es3/Makefile
modified: laboratorio/lab5/es3/src/es3.c
new file: "laboratorio/lab5/es3/src\200student/student.c"
new file: "laboratorio/lab5/es3/src\200student/student.h"
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: laboratorio/lab5/es3/src/student/student.c
modified: laboratorio/lab5/es3/src/student/student.h
deleted: "laboratorio/lab5/es3/src\200student/student.c"
deleted: "laboratorio/lab5/es3/src\200student/student.h"
bad5e7f1e#DESKTOP-3KR49G0 ~/repos/algoritmi2016
$
I've already tried in the past to ignore this, and push the changes to github anyway, but then the same files/folders are shown in github, although when I click them I get an error page (404 or 500, I don't remember the error code).
Also, if I try to delete these with a del or rm command, it says the file doesn't exist. I don't even know if I can type the character that stands for the \200 escape code.
I might have to try and type that character when I use git rm <PATH/TO/FILE> instead of just trying to do del or rm, that do not work.
Why are these files/folder being created? Is it just a bug?
I'm working with a combination of these tools and programs: cygwin64, mingw64, gcc, make, splint, netbeans, atom (editor), git on Windows 10 x64. Is any of these the cause of the error?
My project folder is under C:\\Users\%USERNAME%\repos\algoritmi2016.
splint and git are installed both with and without cygwin. mingw64 is installed normally on Windows' cmd. gcc and make are installed under cygwin. Most of the time I am just using cygwin which points correctly to the cygwin version of splint, git, gcc and make.
I'm not using the atom shell commands, just the GUI editor.
I used Netbeans and atom only inside the ./laboratorio/lab5/es3 folder of my project. In that folder I have the Netbeans project files .project and nbproject.
On cygwin I have a symbolic link in my cygwin's home folder called repos pointing to my normal Window's %USERNAME%\repos folder. I use this link to navigate with cd quickly to my repos folder.
I tried to remove src\200student/ (is it even a folder?), using git git rm -rf ./*student --cached: it didn't match any file, unfortunately.
Is there something wrong in my setup causing this problem?
These files get added to your commit when you issue the command git add -A. If you don't want them, just don't use the -A option to git add. Instead, I recommend only adding the files that you actually want to add to your git repository, one by one.
I don't know where they are actually coming from, however. My guess is that your IDE creates these files for metadata and / or backup while you have the files open. You probably don't have to worry about them, just don't add them into your repository. Next time you want to add somefile.cpp (and maybe it's header, too), just issue the command to add only that file:
git add somefile.cpp
git add somefile.h
I have two remote repositories. One is private (Bitbucket) and the other public (Github). I had been pushing changes to Bitbucket using Github app and then pushing the same commit to Github repo using Xcode. However, recently I have been unable to PUSH the commits to Github and using SourceTree I get this error message:
This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.
This is how it looks from within SourceTree:
How can I get my Github repo to accept the most recent commits?
You have a pre-push hook which is telling you that you have git-lfs (large file support) enabled for this repository, but that it can't find the git-lfs program on your computer. The solution is to either remove the hook (which is located in .git/hooks/pre-push, as the error message says), or to fix your PATH so that it can find the git-lfs program.
It would have been enough to say that the .git directory is in the original local directory of your repository and you probably need a program like TextWrangler or similar, that shows the hidden files starting with a dot, to be able to see it and delete it by moving it to the trash (right click mouse). It took me one hour to figure out this. I hope no one else have to waste that time.
Here is the instructions for removing the pre-push file using Mac Terminal:
First: cd to the directory that is your local repository for your project. (The main folder that holds .xcodeproj and other files) The .git file is hidden but you can still access it by typing cd .git/hooks in terminal. If you type ls in terminal to view all files within the current directory, you'll notice the pre-push file. Type rm pre-push to remove the file. You should now be able to push to your remote repository. Just be sure to cd .. back a few times to your local directory for your project. Simple as that.
I have just recently backed-up my XCode C++ project on my pendrive, using
rsync -avu
Since then, the version control for my project is grayed-out on every files, I can modify the files and not see the "M" nor the "A" sign. The only files still having version-control working "shared" files for which it works correctly. (Those shared files belong to a different project called "Shared").
I have tried git commit -m, git add . and even git init where the files were. Nothing worked.
Can you please help restoring version control for my project?
UPDATE:
Answers for the questions in commens (and answers):
my git repository is on my local hard drive.
I went to the Organiser-repository pane in XCode and I see my recent git commit -m "sth" as "sth" az a commit. I have a single branch: master.
Im not sure what command would be good to test git, as my commits work (theoretically).
I have a folder named .git in the project folder.
git log is working, showing the same as XCode Organiser-repository pane.
I think the XCode just can't synchronise with the git for some reason, and I don't know how to correct that.
First off, this is not an answer that will fix your problem, I just try to provide some help that might get you closer to a diagnosis.
Git stores its files in a folder named .git. Check if this folder is present in your project. If it's not then your Git repository is gone.
Next, try some basic command such as git log. For this to work, you must first cd to your project folder (or a subfolder thereof), because whenever you run a Git command it will look for the .git folder in the cwd or a parent folder. If git log does not work then your Git repository is broken in some way. Someone else will have to step in to further diagnose the problem, as I am no expert on this subject.
Finally, you should also check whether your rsync command has really sync'ed your project's .git folder with the backup's .git folder. Use this command:
diff -rq /path/to/project/.git /path/to/backup/.git
If there is no difference (as I would expect if rsync has worked correctly) then the problem with your Git repository is both in your project and in your backup. If there are differences then it might be worthwile to try your next steps on a copy of the backup (it should be fine to make the copy in the Finder).
Good luck.
I am new to Git, and this is my first project using Git rather than SVN as my source control. I am working in XCode on an iPhone project. I want Git to ignore the build directory, which is in the root folder of the XCode project. I've found several other questions here and also found articles on google that provide examples on how to create the .gitignore file in the root directory and then add it to the Git repository to get the directory to be ignored.
Here are the steps I'm taking when setting up the repository:
Open Terminal and navigate to the root directory of the application
Call git init to initialize the repository
Call git add .gitignore to add the gitignore file
Call git commit -m to commit the gitignore file
Call git status to view the status of the repository
At this point, all of the other directories and files listed in my gitignore file are properly ignored except the build directory. Here is what my gitignore file looks like:
build/
.DS_Store
**/*.pbxuser
*.mode2v3
*.mode1v3
**/*.perspectivev*
I have tried ignoring the build directory using the following different entries with no success:
build
build/
build/*
Anyone know what I'm doing wrong here?
build/ or build/* should be enough to ignore the directory.
See also "Difference between .gitignore rules with and without trailing slash like /dir and /dir/"
The only reasons it could be still not ignored at this point if it:
has somehow been added to the index and committed (which, according to your setup, shouldn't be the case)
has a trailing space (/build ) in the .gitignore file rule, as in this .gitconfig, before Git 2.0 (Q2 2014).