Git not tracking a file from a folder - contents.json from .xcassets - xcode

I have checked almost all the questions on SO but nothing has worked for me. The issue that I'm unable commit the Contents.json file of .xcassets whatsoever. Whenever I add new images to .xcassets the source control does list the images but not the Contents.json file. I'm using a bitbucket repository and not even SourceTree is showing this file in the uncommitted changes. Even tried adding all the files via terminal.
git add --all
Any guess why this is happening and what could possibly be the solution?
Update: The .gitignore file looks like:
ProjectName.xcworkspace/xcuserdata
ProjectName.xcodeproj/xcuserdata
*.xcscheme
xcschememanagement.plist
And .git/info/exclude looks something like:
.DS_Store
UserInterfaceState.xcuserstate

A lot of time has passed, but it seems I know what it is. I encountered the same problem, and every time I added resources, I had to manually do the following steps: git add -f
However, I found out about the command: git status --ignored
The command shows all ignored files. After that, I made the git add -f command manually, and it worked.

Probably you have .xcassets/Contents.json in one or more of the three ignore files .gitignore, .git/info/excludes and ~/.gitexclude.
If that is not the case then try executing below command which will ask Git to start tracking the file again:
git update-index --no-assume-unchanged <file>
For your case:
git update-index --no-assume-unchanged .xcassets/Contents.json

Related

fail to clean file using git command

After merging, I checked with git status and cleaned with git clean -rf, but I was still left with the following untracked file:
<projectName>.xcodeproj/xcuserdata/<username>.xcuserdatad/xcdebugger/
I then checked to see if it would be cleaned with git clean -n, and there was nothing shown, as expected (since it was not cleaned in the previous command).
Also, I have tried an alternative, that I touch .gitignore and added xcuserdata in the .gitignore file. Afterwards when I checked for git status, the untracked file becomes .gitignore, effectively substituting the previous untracked file, which still did not really solve my problem.
What should be the way so that I can clean up my working tree?
It seems the directory is generated by xcode when xcode is running. Close xcode and try git clean -df in the console. If it can be removed properly, add it to .gitignore.
To ignore .gitignore itself, you can add the line .gitignore to the file .gitignore. Another solution is to add and commit .gitignore.

What is the purpose of pom.properties in STS?

Hi, I'm making a Spring project now with STS and Git.
However, whenever I try to do Git Push,
I discover that pom.properties file that I've never worked on is always automatically modified.
1.
So I always ignore it by Git Stash clear or Git Reset.
Is it a smart action?
2.
By the way, what is the purpose of pom.properties file?
I've tried to find the answer on the net, but I couldn't.
Spring help guide also doesn't give me the answer.
I'd be happy if I can get your answer.
As seen in "Version Informations Into Your Apps With Maven", this file would be used to show a version information in a kind of About Dialog or may be on command line as well.
That file is created by an archive step.
If you wanted to ignore it, you could do:
git rm --cached pom.properties
echo pom.properties>>.gitignore
git add .gitignore
git commit -m "Ignore pom.properties"
git push
That way, the file would still be generated/modified, but would no longer be tracked by your Git repository.
As commented by Ralph, the all target folder should not be in Git (since it can be rebuilt every time)
git rm -r --cached target
echo target/>>.gitginore
git add .gitignore
git commit -m "Ignore target folder"
git push

How can I fix error: pathspec 'git-practice-project/git-practice-project' did not match any file(s) known to git

I've created a project to practice using Git with Xcode and GitHub. After a lot of work, I've got the repositories created both locally and remotely. I just tried to make a commit and got this error:
Here's what I'm trying to commit:
The last things I did before I got this error were:
I added a .gitignore file using the GitHub Swift template in order to remove the .xcscheme file from the cache
from the Terminal, I ran 'git rm --cache'
I created the test_file and then tried to Commit
But I can see the folder in the finder:
I looked around SO a lot and found many questions about git commit problem but what I found had mostly to do with diacritics and other issues that aren't the same as mine.
Did the 'git rm --cache' lead to this situation? What can/should I do to safely correct this problem?
Thanks
Update: Seems I really got myself into pickle. I've got nested 'git-practice-project' directories several levels deep:
I've started at the deepest directory, did an ls, and a git status, the backed myself up to the top doing the same thing at each level. It looks like only the two highest directories have uncommitted changes and the project.pbxproj file exists in both of them.
I don't use Xcode's SCM features so I am not sure why Xcode is confused here. But it looks like the files under git-practice-project/git-practice-project aren't known to git yet. You need to add the directory to git. On the command line from the project's root directory you could try:
git status
That should list your files that have been modified, deleted, and that aren't part of the git repo yet.
Add the directory and its contents:
git add git-practice-project
Once you have done that, you should be good to go to use the SCM tools in Xcode again.
Update: In Xcode, you can select the file that is marked with the ? and then go to the Source Control menu and select Add Selected Files.
Ran into this with Xcode 10, with newly added files. You first need to add the new files to the repository. Simply select the file in the navigator on the left, right-click, then Source Control in the pop-up, and select "Add Selected Files". After this the commit will work.

Undo a git clean command?

I just used a "git clean" command and managed to delete my Documents, Music, and other directories. Is there a way to undo this and somehow get those files back? I did this via Terminal on Mac. Time Machine isn't setup either.
I'm afraid those files are gone. git clean is not reversible since those files were not tracked by git.
From the comments it looks like you had your home folder as git repo, but with nothing tracked.
Running git clean -f removed any file inside the home folder (included the one in the subdirectories), leaving only empty subdirectories (the -d option is required for removing them too).
I'm sorry to inform you that you definitely wiped out your whole home directory. Next time you run a git clean use the -n options to perform a dry run and check what's going to happen before it's too late.
Unfortunately git clean removes all the untracked files, meaning the files that are deleted are not able to be recovered using git. You might be able to check your trash to see if the files still exist there.

How to restore version control in XCode?

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.

Resources