Git clean single untracked file - macos

I would like only a certain file to be untracked unlike
git clean
which will remove all untrack files. Thus what is the best way to do that.
Thanks.

Delete it (with rm or whatever facility your OS provides for deleting files).
If you want to keep the file, add it to the repo's .gitignore file, and Git won't try to track it anymore.

#mlpadi answer is correct as well. In this case though what I was looking for was
git clean -f {dir_path}
It helped me clean the files from that 1 folder it was complaining about

Related

Can't get Xcode / JUCE / .gitignore to work

I'm placing my .gitignore file in the same location as the *.jucer file and the .gitignore file contains:
./Builds/*
./JuceLibraryCode/*
As I only want to back up the source code folder only.
But whenever I go to commit, tons of of folders and items inside the Builds and JuceLibraryCode folder are pre checked. How Can I get Xcode to see this ignore file? Is it in the wrong location since the Projucer builds the folder hierarchy in a way that Xcode doesn't understand? I have it in the same location as my .git file.
Also, its worth noting that I recently allowed .git to back up everything, all of the files I'm currently trying to now ignore in those folders, but I did do a git rm --cached on all the files I'm trying to skip, as i read I needed to dump those before the .gitignore would be successful, but still, not luck. Any help would be greatly appreciated.
Remove git cache again.
$ git rm --cached -r .
Add this in .gitignore
Builds/
JuceLibraryCode/
See if git ignore the changes
$ git status

Touch all files in a git repo so git thinks they are changes

I need 'touch' (I think) all files in my git repo (lots of files) so that running git status will have them as modified (and then I can add and commit them). I need to do this because our in-house tool uses the files from a git commit to generate a report ... which I've been asked to do
In posix environments I think I could just touch a directory and go from there.
I don't think that's possible because git detect that a file change if the content of the file changed. Touching the file will have no effect (even on unix).
Perhaps changing the permission on the file could be a very dirty solution but I'm not even sure of that and that's if you find a new permission that don't introduced some bad side effects!
The better solution is to update your reporting tool.
And being obliged to commit changes for ALL files to trick your tool and dirty your history is in my opinion a very bad idea...
If you were asked to "generate a report with all files" does that mean list all files in a commit? Cause that's easily done with something like a git ls-tree -R HEAD
I had a demo repo that had a bunch of files in it, that had commit messages that I didnt want showing up in the demo - and to be clear, the repo was "garbage", in that it was just basically a dump of files to demonstrate a folder structure.
That having been said, one way you could do this is to
create a new temporary folder in your repo, for example "ez"
move all the files of the repo into it, e.e. "$ mv * ez"
commit that locally, the do the reverse and move them out again
"$ mv ez/* .; rmdir ez"
That would show all files as having been changed. For my purposes, I then committed that change too, and pushed it up to my demo repo.

Untrack all files on git

In the move from C9 to hosting on my Macbook via SSH, I've had to re-download Kohana and change some other things just to get my site working; I don't want those to be committed. Is there any way to untrack all tracked files so only future changes are committed? Or is there something else I should be doing?
I'm on a Macbook running Mountain Lion with Apache and PHP turned on.
Even simpler:
cd /root/directory/of/your/local/repo
git rm --cached -r .
^^^
(space - dot)
Even even simpler:
git clone url/for/Kohana /different/local/path
git rm --cached File
Will delete the file in the index, so it will no longer be tracked, but won’t physically delete it. This will untrack the file only for current branch
[OR]
Use this git command. After you do this, git stops checking the file for possible modifications.
git update-index --assume-unchanged <filename>
At any time, you can track again by setting --no-assume-unchaged flag
git update-index --no-assume-unchanged <filename>
But these command do not affect the remote repository.
I'm not exactly sure what you mean by "untrack all tracked files so only future changes are committed". As you need to track files so they can be committed.
If all you just want to do is not track Kohana and the other downloads, then just remove them from your working directory using git rm --cached <file> or even better create a .gitignore file.
There are many helpful posts on stackoverflow to assist you with creating a .gitignore file for your project. By using this, you can exclude an entire folder easily.
For Mac, it would also be helpful if you could see hidden file as the . file is hidden. This page shows you how to see hidden files on Mountain Loin - http://www.mikesel.info/show-hidden-files-mac-os-x-10-7-lion/

How to get Git on Windows to ignore symbolic links

I can't get this to work.
I have cloned a repository that has a dummy file (named src): /path/src.
On Windows I have created a symbolic link: mklink -d /path/src /otherplace/src (but I of course had to delete the dummy src file first).
In both my .gitignore and .git/info/exclude I have
/path/src/
/path/src
path/src/
path/src
And I have tried
git ls-files -s | gawk '/120000/{print $4}'
git update-index path/src/ --assume-unchanged
but I still get:
error: readlink("path/src"): Function not implemented
error: unable to index file path/src
fatal: updating files failed
I have tried all these other suggestions. And even this doesn't work.
Any ideas?
You can do a checkout ignoring this single file like this:
git checkout HEAD . --no path/src
The .gitignore file only works for adding stuff to the index. Even a modifications on files commited before adding it to the .gitignore are not ignored.
I know this is late, but I ran into this issue.
In my case, I apparently had checked in my symlink at some point. So no matter what I did, .gitignore would not work (I think that is what Alexandre was getting at).
REPAIR:
Remove all symlinks
See if git now thinks there are deleted files to commit.
If so, then go ahead and commit the deletions.
Now you can re-add your symlinks and .gitignore should work.
Here are my steps for this issue, similar, but a bit different from other answers.
Let's say I had a folder .fvm contain file.json and flutter_sdk(link) that all commited in git before, then I want to ignore out flutter_sdk.
Add .fvm/flutter_sdk and .fvm/flutter_sdk/ in .gitignore.
Cut .fvm/flutter_sdk out to other place than the repository.
git add . and git commit ....
Paste back the link.

Ignoring directories in Git repositories on Windows

How can I ignore directories or folders in Git using msysgit on Windows?
Create a file named .gitignore in your project's directory. Ignore directories by entering the directory name into the file (with a slash appended):
dir_to_ignore/
More information is here.
By default, Windows Explorer will display .gitignore when in fact the file name is .gitignore.txt.
Git will not use .gitignore.txt
And you can't rename the file to .gitignore, because Windows Explorer thinks it's a file of type gitignore without a name.
Non command line solution:
You can rename a file to ".gitignore.", and it will create ".gitignore"
It seems that for ignoring files and directories there are two main ways:
.gitignore
Placing .gitignore file into the root of your repository besides the .git folder (in Windows, make sure you see the true file extension and then make .gitignore. (with the point at the end to make an empty file extension))
Making the global configuration ~/.gitignore_global and running git config --global core.excludesfile ~/.gitignore_global to add this to your Git configuration
Note: files tracked before can be untracked by running git rm --cached filename
Repository exclude - For local files that do not need to be shared, you just add the file pattern or directory to the file .git/info/exclude. Theses rules are not committed, so they are not seen by other users. More information is here.
To make exceptions in the list of ignored files, see this question.
To ignore an entire directory place a .gitignore of “*” there.
For example,
Example System
/root/
.gitignore
/dirA/
someFile1.txt
someFile2.txt
/dirB/
.gitignore
someFile3.txt
someFile4.txt
Goal
ignore the contents of dirB/
Top Level (/root/.gitignore)
You could just “dirB/“ here
Ignored Directory (/root/dirB/.gitignore)
Or you could “*” here
Git watches for gitignore at every step of the file system. So here I choose dirB/.gitignore as “*” to ignore dirB/, including all files and subdirs within.
Done ☺️
To instruct Git to ignore certain files or folders, you have to create .gitignore file.
But in Windows Explorer you have to provide a name for the file. You just cannot create file with just an extension. The trick is that create a empty text file and go to command prompt and change the name of the file to .gitignore:
ren "New Text Document.txt" .gitignore
Now open the file with your favorite text editor and add the file/folder names you wish you ignore. You can also use wildcards like this: *.txt.
I had some issues creating a file in Windows Explorer with a . at the beginning.
A workaround was to go into the commandshell and create a new file using "edit".
If you want to maintain a folder and not the files inside it, just put a ".gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository. But .gitignore will be included in your repository.
$ git add path/to/folder/.gitignore
If you add an empty folder, you receive this message (.gitignore is a hidden file)
The following paths are ignored by one of your .gitignore files:
path/to/folder/.gitignore
Use -f if you really want to add them.
fatal: no files added
So, use "-f" to force add:
$ git add path/to/folder/.gitignore -f
You can create the ".gitignore" file with the contents:
*
!.gitignore
It works for me.
In Windows there's an extra catch with slashes. Excluding a single directory in .gitignore with
dir_to_exclude/
will possibly work, but excluding all directories with
/
causes problems when you have file names with spaces (like my file.txt) in your directory: Git Bash escapes these spaces with a backslash (like my\ file.txt) and Git for Windows doesn't distinguish between / and \.
To exclude all directories, better use:
**/
Two consecutive asterisks signify directory contents.
Just in case you need to exclude sub folders you can use the ** wildcard to exclude any level of sub directory.
**/build/output/Debug/
Also in your \.git\info projects directory there is an exclude file that is effectively the same thing as .gitignore (I think). You can add files and directories to ignore in that.
When everything else fails try editing the file
/.git/info/exclude
and adding the directories you want to the end of the file, like this:
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
assets/
compiled/
I added the folders "assets" and "compiled" to the list of files and directories to ignore.
I've had some problems getting Git to pick up the .gitignore file on Windows. The $GIT_DIR/info/exclude file always seems to work though.
The downside of this approach, however, is that the files in the $GIT_DIR directory are not included in the check-in, and therefore not shared.
p.s. $GIT_DIR is usually the hidden folder named .git
On Unix:
touch .gitignore
On Windows:
echo > .gitignore
These commands executed in a terminal will create a .gitignore file in the current location.
Then just add information to this .gitignore file (using Notepad++ for example) which files or folders should be ignored. Save your changes. That's it :)
More information: .gitignore
I assume the problem is that your working tree is like:
a-cache/foo
a-cache/index.html
b-cache/bar
b-cache/foo
b-cache/index.html
.gitignore
... with the .gitignore you describe. This will give you git status output like:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# a-cache/
# b-cache/
... if the index.html files have not yet been added to the repository. (Git sees that there are unignored files in the cache directories, but it only reports the directories.) To fix this, make sure that you have added and committed the index.html files:
git add *cache/index.html
git commit -m "Adding index.html files to the cache directories"
... and your git status will then look like:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)
(Obviously you do want to commit .gitignore as well. I was just being lazy with this test case.)
On Windows and Mac, if you want to ignore a folder named Flower_Data_Folder in the current directory, you can do:
echo Flower_Data_Folder >> .gitignore
If it's a file named data.txt:
echo data.txt >> .gitignore
If it's a path like "Data/passwords.txt"
echo "Data/passwords.txt" >> .gitignore.
I had similar issues. I work on a Windows tool chain with a shared repository with Linux guys, and they happily create files with the same (except for case) names in a given folder.
The effect is that I can clone the repository and immediately have dozens of 'modified' files that, if I checked in, would create havoc.
I have Windows set to case sensitive and Git to not ignore case, but it still fails (in the Win32 API calls apparently).
If I gitignore the files then I have to remember to not track the .gitignore file.
But I found a good answer here:
http://archive.robwilkerson.org/2010/03/02/git-tip-ignore-changes-to-tracked-files/index.html
Just create .gitignore file in your project folder Then add the name of the folder in it for ex:
frontend/node_modules
This might be extremely obvious for some, but I did understand this from the other answers.
Making a .gitignore file in a directory does nothing by itself. You have to open the .gitignore as a text file and write the files/directories you want it to ignore, each on its own line.
so cd to the Git repository directory
touch .gitignore
nano .gitignore
and then write the names of the files and or directories that you want to be ignored and their extensions if relevant.
Also, .gitignore is a hidden file on some OS (Macs for example) so you need ls -a to see it, not just ls.
Temporarily ignore a directory/file that was already in git:
I have a lot of projects in a multi-project gradle project and they can take a long time to delete them, and they're all pretty much the same but different. From time to time I want to remove those from the gradle build by deleting them altogether. git can get them back after all. However I don't want them showing up in git status either. So I use the following simple procedure;
delete files and folders I don't want.
verify build still works
tell git to ignore the deleted files for a bit (we can get them back)
git ls-files --deleted -z | git update-index --assume-unchanged -z
--stdin
go about life without the dirs until you want them back. Then run the same command as before but switch out assume-unchanged for no-assume-unchanged
git ls-files --deleted -z | git update-index --no-assume-unchanged -z
--stdin

Resources