According to this QA, we may use safe.directory argument to add directory to be marked as whitelist, due to latest CVE found on git. But it seems there is no way to add certain dirs recursively.
I have so many repositories to add, so i want to use recursive add instead, if the feature is exist. The repositories mostly placed on my mounted NTFS disk on ubuntu, so the owner of files inside is always root. Looks like the latest update restricts git operations if the logged in user is not match with owner of the git directory by showing error such fatal: unsafe repository ('/media/data1/project1/si/project' is owned by someone else.
From Git 2.36, you can also add * representing 'all' to the safe.directory. It's not recursive as you asked, but it may help depending upon your situation i.e.
git config --global --add safe.directory *
See https://github.blog/2022-04-18-highlights-from-git-2-36/ and search for safe.directory.
What I did for now, but may not be the perfect solution, is to find all .git folders and add them through a find command.
find /full/path -name '.git' -type d -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
Want to remind, that it is necessary to add the full path in the find command, so it will resolve the full path.
Related
I have a directory like that :'dir1/dir2/blah.blah.blah.blah/'
'blah.blah.blah.blah' is folder how do I add it to .gitignore?
I tried:
dir1/dir2/blah.blah.blah.blah/*
You need to escape the . in your .gitignore file like this:
blah\.blah\.blah\.blah
If this does not work, you probably added the directory to git earlier. In this case, you need to remove it from git (git rm <directory> and then git commit) but this will also remove it from the working directory, so backup the files if you still need them!
Use git ls-files dir1/dir2/ as suggested by torek in the question's comments to check if the directory has been added to git.
To remove a file or directory from repository, you can use this:
git rm -r --cached <file/directory>
git commit -m "removes <file/directory>"
This will not remove anything from the history though. The files can still be accessed when checking out an older commit.
It will also not remove the actual files in the directory, it will just make git not longer track them.
I need to remove these Iconr files from the project\commit but I cant find them in the project folder (even in the hidden files).
I can't perform any commit with these files, how can I remove them?
These files are created by some external apps such as Folderol which are used for highlighting/coloring your folders. Remove that app, or add these files into gitignore files, either to:
.gitignore inside your repository root,
global .gitignore, e.g.
git config --global core.excludesfile ~/.gitignore
into explicit repository exclude file (.git/info/exclude) inside your repository root.
See: Using Git / Ignoring files
To delete them, try:
find . -type f -name 'Icon??' -print -delete
I misplaced a file somewhere in a branch of one of the many repos I have on my system. I'm not even sure what repo it was, but I think I'll recognize the branch name if I see it.
Is there a way to print out a list of all of my repos and each of the branches they contain?
This command will do the trick:
find ~ -type d -name ".git" -print -exec git --git-dir={} branch \;
This searches inside your home directory for every directory named .git. For each matching directory, it prints the directory name and then runs git branch to list its branches, passing the directory name to that command.
Since we are searching for the .git subdirectory and not the repo root directly, the directory name printed and passed to git branch includes the .git subdirectory at the end. I thought it might be necessary to remove this from the directory name, but git branch works fine with it, so this simple command is good enough.
I'm using git on windows with the git bash and every time I want to autocomplete a filename in a git command I get fatal: Not a git repository: '.git' posted between my already typed characters and the completed ones.
It looks like this:
$ git diff a
<using tab>
$ git diff afatal: Not a git repository: '.git'
pp.js
I can still make the command properly by just pressing enter as expected. But it really starts to get on my nerves.
Any suggestions?
The problem was an extra .git-folder in my src folder. The repository was initialized on the folder above (src/..) and this seemed to mess with git. After the removal of the extra .git folder the problem disappered.
I just discoverd the solution. I had an extra .git directory in my src-folder which seemed to mess with git (the repository was initialised on the folder above).
After I removed the extra .git folder the problem disappered.
It can depends on the msysgit version you are using:
I just tested a tab completion on a git diff on W7 64bits, with the latest msysgit1.8.3, and it worked just fine.
Don't forget that, in addition to the msysgit version, you will have issues with tab completion due to the old bash 3.1 included in mysysgit.
And the completion can be slow on Windows.
As the OP Zeeker mentions below, the completion git-completion.bash is based on a proper git repo path detection.
# __gitdir accepts 0 or 1 arguments (i.e., location)
# returns location of .git repo
__gitdir () {
...
}
And in Zeeker's case, an extra .git folder was in the src folder, which means any completion was based from the wrong folder, which, for git diff, proved fatal.
git add seems to work though.
git-bash completion for git commands is controlled by the /etc/git-completion.bash. To fix run git-bash as administrator, then:
cd /etc
mv /etc/git-completion.bash /etc/git-completion.bash.orig
Then create a new one from the contents of https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
This question already has answers here:
How to make git ignore changes in case?
(6 answers)
Closed 10 months ago.
There are a couple of files in our git-controlled codebase that I'd like to rename. Specifically, I just want to change the case of the file, so that sourceCode.java becomes SourceCode.java, for example. The catch: I'm on a Windows box, and the filesystem thinks those are the same file name.
How can I get Windows and Git to recognize that change and check it in?
The change of the file name should not be ignored, but committed to git.
To rename the file you can use the standard git mv command.
Since Windows treats files with only changes in case as identical, you have to pass the -f option to force a rename:
git mv -f name.java Name.java
If instead you want to ignore case changes, have a look at the question
How to make git ignore changes in case?.
If you are on a FAT file system your only choice is to do a two stage rename:
Rename sourceCode.java to anything.you.like
Rename anything.you.like to SourceCode.java
Back in the days when we used Perforce we had exactly this problem and this was the only solution we could come up with.
The following steps allowed me to change the case on Windows:
Add ignorecase = false to [core] in .git/config;
Move the files you are going to rename out of your project directory;
Add the deletes to the index;
Move all files back to their original location and change the case of the files and/or directories;
Add all "new" files to the index;
Remove ignorecase = false added at the first step.
This way you have a single commit that contains the rename and it makes it easy to change e.g. an entire directory.
In my opinion one simple way is missing. You can do this for a single file, a specific directory or even the whole repository. Just rename your files in any way you like before and than execute these commands:
git rm --cached <file name or directory>
git add <file name or directory>
If you want to affect also the sub-directories, you have to use the -r flag:
git rm -r --cached <directory>
git add <directory>
Be careful. Doing this can lead to changes that are impossible to merge. Git gets confused when merging on Windows because it can't decide whether the old Uppercase name and the new lowercase name are the same file or not (for Git they are not, but for the filesystem they are). To merge you have to do some manual workaround like deleting the files before merging.
See Git rebase issue with files of same name but different case
I'm not sure if this issue is worse than having an unconventionally-named file in your project for ever and ever, but it is worth knowing about if there are lots of users with lots of branches which will all need to be merged eventually.
With NTFS (or FAT), a single git mv command does not solve the problem.
This question shows a technique that works:
git mv and only change case of directory