Dropping files inside gitignore path onto Xcode - xcode

Each time I try to add a file to my resources which is in gitignore Xcode keeps telling me
"The following paths are ignored by one of your .gitignore files:
res
Use -f if you really want to add them.
fatal: no files added"
So I add my resources by removing the res folder from gitignore, then dropping the file onto Xcode, and finally adding the res folder again to gitignore and removing any stage changes.
Is there a better way to do this procedure?
I'm keeping my res folder in gitignore because of too many binary files, otherwise the git folder would start to increase its size astronomically

You can add them by using the --force flag on add:
git add -f res/foo
git commit -m "more resources"
(or by using wildcards, e.g. git add -f res/*)
Bonus tip: If you want to list the files that have been committed even though they match gitignore, you can do
git ls-files -i --exclude-standard

Related

"git add ." not working

In a folder in my project I am trying "git add images" (images is a folder). Nothing happens. I also went into the images and ran "git add ." and nothing happened.
In both cases "git status" tells me my branch is up to date.
What do I need to do?
First, if images/ is an empty folder, Git would not add it: it adds only files.
Adding just a folder requires indeed adding a file, like a .keep, or a .gitignore if you don't want to track its content.
Second, if images/ is a folder with files, and those files are not added, pick one of those untracked file (that you cannot add), and type:
git check-ignore -v -- images/afile
That way, you won't have to check all .gitignore files: Git will do that for you, and print any .gitignore path (and the rule in it) which is responsible for images/ content (the files) to be ignored (you would need to do git add -f to force them to be added)

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

Changing case of Folder via Git bash on Windows

I need to change the case of folders and files. First thing I tried was renaming the folders, but Git didn't pick up the changes. So I tried using git mv -f controller Controller but it says :
fatal: renaming 'application/classes/controller failed: Permission denied
I have tried setting the global ignorecase flag:
git config --global core.ignorecase false
But it still doesn't work. Some people have suggested to move the folder out of repo, delete, then re-add but would this change get picked up when other people pull the repo? Is there anything else I could try?
Edit: It works for files but not folders.
In summary of the comments, you'll have to rename the directory via a intermediate temporary name. E.g.
git mv controller Controller-tmp
git mv Controller-tmp Controller
I think this has to do with the fact that the MinGW implementation of rename(2) does not support this operation. See this thread, the MSDN docs on the CRT rename implementation and those of the MoveFileEx function.
Make sure to close Visual Studio and any Windows Explorer folders related to that path.
Make sure to add the changes to index after rename folder with intermediate folder as below.
git mv oldfolder newfolder
git add -u newfolder
git commit -m "changed the foldername whaddup"
Reference
I could not resolve this apart from performing the following
Branch from commit before folder name case changed, as a temp branch just to resolve this issue.
Cherry picking commits in order resolving folder case name changes before committing.
Reset old branch this new temp branch final commit.
Remove temp branch.

Can't ignore UserInterfaceState.xcuserstate

I'm using Git for Xcode 4 project version control. I've explicitly added ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate to .gitignore, but Git it won't ignore it. Any ideas why this is so?
Git is probably already tracking the file.
From the gitignore docs:
To stop tracking a file that is currently tracked, use git rm --cached.
Use this, replacing [project] and [username] with your info:
git rm --cached [project].xcodeproj/project.xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"
Alternatively you can use the -a option to git commit that will add all files that have been modified or deleted.
Once you've removed the file from git, it will respect your .gitignore.
In case that the ignored file kept showing up in the untracked list, you may use git clean -f -d
to clear things up.
1.
git rm --cached {YourProjectFolderName}.xcodeproj/project.xcworkspace/xcuserdata/{yourUserName}.xcuserdatad/UserInterfaceState.xcuserstate
2.
git commit -m "Removed file that shouldn't be tracked"
3.
WARNING first try git clean -f -d --dry-run, otherwise you may lose uncommited changes.
Then:
git clean -f -d
All Answer is great but here is the one will remove for every user if you work in different Mac (Home and office)
git rm --cache */UserInterfaceState.xcuserstate
git commit -m "Never see you again, UserInterfaceState"
Had a friend show me this amazing site https://www.gitignore.io/. Enter the IDE of your choice or other options and it will automatically generate a gitignore file consisting of useful ignores, one of which is the xcuserstate. You can preview the gitignore file before downloading.
In case the file keeps showing up even after doing everything mentioned here, make sure that this checkbox in Xcode settings is unchecked:
Just
"git clean -f -d"
worked for me!
Here are some demo & short cuts if you uses GitHub, the basic ideas are the same.
1. Open terminal like this
2. Paste the below command to terminal followed by a space and then paste the path of the .xcuserstate file simply like this
git rm --cached
3. Make sure you have the correct git ignore and then commit the code :)
This works for me
Open the folder which contains the project file project.xcworkspace from the terminal.
Write this command: git rm --cached *xcuserstate
This will remove the file.
For me nothing worked, but this
add this line to your gitignore
*.xcuserdata
Here is one more simple solution if you are using the source tree app.
here are the instructions
1.Right-click on the file which you want to add to the git ignore list and select stop tracking.
again right-click on the same file and you will notice ignore option is now enabled then click on ignore button.
now you can reset or commit your changes for the same file it depends on whether your changes are important or not. changes in the future will not be tracked for the selected file.
Here is a very nice explanation of how to remove the files in question recursively from your git history: http://help.github.com/remove-sensitive-data/
Very useful, because otherwise tools tend to 'hang' while trying to show the diff on those huge files that shouldn't have been checked in the first place...
Here's what you can do (in short) to get rid of the largest stuff:
cd YourProject
git filter-branch --index-filter 'git rm --cached --ignore-unmatch -r YourProject.xcodeproj/project.xcworkspace' HEAD
# see what you want to do with your remote here...
# you can: git push origin master --force
# or you can delete it and push a fresh new one from your cleaned-up local...
rm -rf .git/refs/original
git gc --prune=now
git gc --aggressive --prune=now
Worked very nicely for me :)
For xcode 8.3.3 I just checked tried the above code and observe that, now in this casewe have to change the commands to like this
first you can create a .gitignore file by using
touch .gitignore
after that you can delete all the userInterface file by using this command and by using this command it will respect your .gitignore file.
git rm --cached [project].xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate
git commit -m "Removed file that shouldn't be tracked"
You can also ignore files from Xcode preferences itself.
Generate gitignore file from https://www.toptal.com/developers/gitignore
Go to Xcode -> Preferences -> Source Control -> Git -> Add all ignore items in the list...Even though UI is not really useful & you have to add all items individually but adding ignore files here surely works.
I think it would be better to write like this.
git rm --cache *//UserInterfaceState.xcuserstate**

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