Git made 3 Gits And Now Not Working At All - xcode

Help!
I implemented Git to my project and somehow Git has made 3 files for saving my information: (1) Saves all of my view controllers, (2) The same file as (1), (3) my pods only.
The one containing my pods seems to be broken as I can not commit anything to it. First I thought nothing of these 3 Gits and proceeded coding, but now I am trying to branch my master with something I have been spending months coding but it seems to be crashing every time because it does not save my code to the master and makes me update my pods. Now after I tried to branch it, it did not work but now when I try to commit my files to the current branch I'm working on, it is not letting me without committing all 1600 files that are in my Pods. But the Pod file will not commit! I have no clue how to fix this and I am in desperate need of help!!!! Can anyone please help. I just want to have one place that will commit my files like in every Xcode git file. I do not want to lose my months of work.
I get the error: "The working copy “Pods” failed to commit files. - The source control operation failed because no repository could be found."

Please trouble shooting you issue with below aspects:
1. Use one git repository
If you mean 3 gits are 3 git repositories, you should keep only one git repo to manage your project. Only keep the repo that can contain all the files you want to manage under it’s directory.
As below example, if you project (the files you want to manage in git repo) is under Dir2 (not contains it’s parent Dir1), then you should remove the other two repos for Dir1 and Dir3 by removing the folders Dir1/.git and Dir1/Dir2/Dir3/.git.
Dir1
|___.git
|___ …
|___Dir2
|___.git
|___ …
|___Dir3
|___.git
|___ …
If you mean 3 gits are 3 git branches for the same git repo, before switching branches, you should make sure the work directory is clean (save and commit changes before switching branches).
2. Mark sure user.name and user.email has already been set
You can use the command git config -l to check if the output contains:
user.name=<username>
user.email=<email address>
If the output does not contain user.name and user.email, you should set as below:
git config --global user.name yourname
git config --global user.email xxx#xx.com

Related

Cannot git checkout master: invalid path '?'

After an "unsuccessful" git pull on my local master, an error prevents to switch back to master:
C: repo_folder> git checkout master
error: invalid path '?'
The ? must be because it is a keybase repo.
From another branch where I checked out some files of the last commit:
C: repo_folder> git diff origin/master --compact-summary
"\004" (gone) | 1902 ---------------------------
some irrelevant stuff | (num) -
The removed file "\004" (that was never present in my local) seems to come from some Mac OS (someone might have opened a csv and a temporary file was created when that user did the commit and pushed?).
observe that the file that is marked as (gone) is to be removed by git
the problem is that the filename has characters that are not compatible with the Windows file system and that the file never existed in my local Windows repo.
If I clone from a Linux platform, I can checkout to master with no problems. However, in Windows, there's no way back to the master branch.
Any ideas on how to solve this issue? (already tried some posts with no success)
I can't really understand how it comes git doesn't even allow me to checkout to master. Should I file a bug report?
Alternatively, perhaps I could create a new master branch and get rid of the current one.
EDIT
A clone from Linux helped to identify that the file ? was actually there.
This could be checked directly from Windows as well by using the command: git ls-tree origin/master (which was showing the original problematic name "\004")
The accepted answer includes the case where you want to save the content of the file, while in my case I only wanted to get rid of it. So in my case, I have just deleted the file from Linux, committed and pushed the change, and did a git fetch origin master:master to fetch my local master with being checked out in another branch (as I was not able to checkout to master). This finally did the trick and I could checkout to master.
Hope this clarifies to someone with a similar problem.
? (or maybe it's EOT) cannot be used as a filename on Windows. The file will have to be deleted or renamed. You can do this most easily by cloning on a system which does allow ? and making the fix.
If you only have Windows, Fixing Invalid Git Paths on Windows offers a method of renaming the file without checking it out. In brief...
git checkout origin/master -f to get the checkout without the problematic file.
Make a branch.
Add and commit the "deleted" problematic file.
Use git ls-tree HEAD^ to get the ID of the problem file.
Use git cat-file -p <ID> to get the content of the problem file.
Put the content into a new file.
Add and commit.

Git checkout fails on untracked working tree files after git mv

I have a problem with my local branches. When I am trying to do git checkout <branch> I get this error message:
error: The following untracked working tree files would be overwritten by checkout:
... (list of files)
Please move or remove them before you switch branches.
Aborting
I think that the reason is a fact, that in current branch I've renamed/moved some files with git mv.
All the files listed in this error message are listed with old path (i.e. path before moving / renaming action). Is there any way to work around this problem? I'd like to move to my master branch now, and merge it with current branch, so after that there should be no problem, yet for now, I don't know how to successfully switch branches (and then do a merge, if there might again be some problems).
Edit:
I was able to checkout using -f option, but the problem remains, because now I can't do merge, for the same reasons (actually, now the paths are the opposite, i.e. now error message contains new paths, that were used in database branch) and I don't know an option to force git to do this merging.
I am not sure, but probably the same solution would work for both checkout and merge problem.
Following #LutzBüch comment, I am trying to show exactly what happened in this repo.
I have branches master and database. The database branch worked only on a parts strictly related to database only. This part of code remained in a directory named let's say db. At some point, I had to change this dir name to DB, so I did some git mv's. Let's follow it from last merge, when everything still worked.
git checkout master
git merge database
git checkout database
git commit
{now the renaming happens}
git mv db/. tmp/.
git mv tmp/. DB/.
git commit {no other changes were made}
{added some renaming related changes, i.e. changed paths in 2 files}
git commit --amend
{now it's becoming the standard}
git commit {multiple times}
git checkout master {fails}
Last command failed with error message mentioned earlier. All files on the list had paths with the old dirname, i.e. db. After using git checkout -f master, when I tried to do merge I received paths with DB as the dirname.

"Not a git repository" after OS reset

This morning my Windows 10 crashed and rebooted once I lifted my laptop's screen. No special activity was progressing, so I don't think there was significant disk activity.
However one of my main Git repos crashed after that reset. Here is what I tried:
$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ git init
Reinitialized existing Git repository in ....../.git/
$ git status
fatal: Not a git repository (or any of the parent directories): .git
Loop
I don't think I have unpushed commits, so wiping and cloning from remote should work.
Still, can I ask what to do to recover an existing Git repository (.git directory still exists, chkdsk reports OK) in such cases?
[Add] read this but did not apply to my case (I can't restore the repo)
As kabanus said in a comment, you should definitely save whatever you can before proceeding (and/or use some other existing clone as a backup).
When Git complains about this, though, it often means that the file .git/HEAD has gone missing. If you create a new HEAD file with contents: ref: refs/heads/master, Git may be able to recover everything.
Since HEAD is the most active file in the repository, it's the one most likely to be clobbered by an OS error or power failure. It's also a critical file when it comes to whether Git believes a .git directory is a repository: if the directory contains a file named HEAD (along with a few other key items), it is a repository; if not, it is not a repository.
I had multiple branches corrupt due to OS error (bloody windows sleep function!!). So I had to manually do the following:
.git/HEAD (set content to ref: refs/heads/master)
$> git branch -v (this will tell you all the corrupt branches)
.git/logs/HEAD (Read the file for last checksum of the commits and merge of corrupt branches)
.git/refs/heads/{corrupt branch file} (change the checksum to the last working checksum from the log file.
merge the branches again as per need.
Another workaround for this, Solved for me while OS crashed on GIT MERGE operation
Get the working HEAD,FETCH_HEAD files under .git/ directory(of your project) from some other contributor
Replace the existing HEAD,FETCH_HEAD files with new ones(taken from other contributor).
Delete the INDEX under .git/ directory.
Then Do a git pull.
In my case, the HEAD file was indeed corrupted due to a system crash.
I just cloned the repo again into a new folder, switched to the branch I was in, then replaced the .git folder with the one I just created from the clone.
From there, it was like nothing happened.
In my case, The ownership of the repo was mismatched after OS reset.
I tried #raheel-hasan's instructions, after entering git branch -v command I got a suggestion.
git config --global --add safe.directory 'direactory path' this command solved the issue :)
(Use powershell to run this command)
You shoult reload your IDE or code editor after running this command.

How do I ignore files when pulling from github?

I am working in Ruby and want to ignore my config files when I pull from Github.
The error I am receiving is:
"error: Your local changes to the following files would be overwritten by merge: config/database.yml"
Things I have tried:
1) I added the file paths to my .gitignore located in my application root.
2) I added the file paths to my global .gitignore
3) I ran git update-index --assume-unchanged /config/database.yml from my application root
4) I ran git update-index --skip-worktree config/database.yml from my application root
I have multiple instances of the same application in several different folders on my computer. The other instances of the application respect the assume-unchanged command. Im not sure what I am missing.
Consider stashing your local changes before pulling:
git stash
git pull
git stash pop
It is possible that you have merge conflicts if the files you are stashing are changed on the origin.

Git status is clean even though a file has changed

I have spent a great deal of time since I first started using Git struggling with files being reported as changed when they hadn't been touched, and core.filemode = false resolved those issues... but today I have the reverse problem. (Unless otherwise specified, I'm doing this from Git Bash (1.7.10.msysgit.1) in Windows 7.)
The situation:
On my master branch, I did git pull upstream master to pull the latest changes - this said everything was up to date (I double-checked and the last commit is the same on my local master, my origin fork and the upstream Github repo so I'm reasonably certain this is correct)
I amended an existing file. The diff in TortoiseGit 1.8.0.0 shows the changes, though its overlay still shows the directory as clean. Odd. git status is... still clean. Very odd.
I delete a file: rm Readme.md. File disappears. git status is still clean. Clearly, git isn't actually tracking my files anymore.
(For the record, setting core.filemode = true and then running git status just gave me nonsense about files whose mode changed at some point between my Windows system and Github, but still didn't list the deleted or the truly modified files)
I'm missing something here and I hope someone can tell me what it is! I've done dozens of commits from this machine to that same repository via my fork on Github so I'm reasonably certain this environment works and I generally know what I'm doing, but clearly something has changed that I can't put my finger on right now.
Edit, as requested, my Git workflow as followed in Bash (didn't bother checking out a new branch as the problem occurs in master anyway):
Emma Burrows#PC ~/Documents/Dropbox/gitproject (test)
$ git checkout master
Switched to branch 'master'
Emma Burrows#PC ~/Documents/Dropbox/gitproject (master)
$ git status
# On branch master
nothing to commit (working directory clean)
Emma Burrows#PC ~/Documents/Dropbox/gitproject (master)
$ git pull upstream master
From git://github.com/company/gitproject
* branch master -> FETCH_HEAD
Already up-to-date.
Emma Burrows#PC ~/Documents/Dropbox/gitproject (master)
$ rm Readme.md
Emma Burrows#PC ~/Documents/Dropbox/gitproject (master)
$ git status
# On branch master
nothing to commit (working directory clean)
Readme.md is a tracked file present in both my forked repo on Github and in the original upstream repo. I hope that helps?
NEW EDIT I've moved the folder out of Dropbox to a local folder on a local drive, but the problem remains the same. The .git folder must be poked. I was hoping to find out what was wrong with it though.
Thank you to everyone who tried to help. The problem persisted after I moved the whole folder, including .git folder into another location on my local hard drive. I can only assume that two copies of the repo on different machines had tried to sync the git folder at once and resulted in a broken local repo. I ended up recloning the folder (out of Dropbox for now) and everything is working normally again.

Resources