Git status is clean even though a file has changed - windows

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.

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 made 3 Gits And Now Not Working At All

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

"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.

'git rev-parse --is-inside-work-tree' doesn't recognize working tree or subdirectories

After updating to the latest Windows Git (2.5.0 from 1.6.2) I find I'm unable to rebase a branch:
C:\core\guidewire\Dev\2.4>git checkout fhcf-assumptiondate && git rebase master
Previous HEAD position was d032e17... Merge branch 'de8041'
Switched to branch 'fhcf-assumptiondate'
First, rewinding head to replay your work on top of it...
fatal: C:\Program Files\Git\mingw64/libexec/git-core\git-am cannot be used without a working tree.
Comments on this question hint at a Git installation conflict, but the old version is entirely removed by now, including a lingering DLL and checking for stale environment vars.
Looking inside the git scripts, I find that the error message is coming from a test in git-sh-setup that uses git rev-parse --is-inside-work-tree. Consulting rev-parse directly shows that it seems to not understand that I really am inside the working copy:
C:\core\guidewire\Dev\2.4>dir .git
Volume in drive C is System (Local)
Volume Serial Number is D4EC-4ED4
Directory of C:\core\guidewire\Dev\2.4
08/04/2015 21:16 27 .git
1 File(s) 27 bytes
0 Dir(s) 155,451,965,440 bytes free
C:\core\guidewire\Dev\2.4>git rev-parse --is-inside-work-tree
false
...Except some commands are able to correctly tell the difference:
C:\core\guidewire\Dev\2.4>git status
HEAD detached from refs/heads/fhcf-assumptiondate
nothing to commit, working directory clean
C:\core\guidewire\Dev\2.4>cd ..
C:\core\guidewire\Dev>git status
fatal: Not a git repository (or any of the parent directories): .git
What is making Git confused about whether I'm in the right directory or not?
Possible points of interest:
Repo was created by the previous installation.
1.6.2 was an msys build of Git. 2.5.0 is MinGW.
The repo was cloned with --separate-git-dir.
checkout, status, add, commit and possibly others all have worked without issue since the upgrade.
A clone of the broken repository exhibits correct behavior; 'in' or 'out' of the working tree are detected correctly.
To continue using an existing (1.6.x-created) repository after upgrading to Windows Git 2.5, update the repo's gitconfig:
[core]
worktree = c:/core/guidewire/Dev/2.4
to
[core]
worktree = C:/core/guidewire/Dev/2.4
The new Git installation either obtains paths differently from the old, or is no longer case-insensitive about paths. Therefore the existing repo working tree location becomes wrong since no folder under c:\core\guidewire\Dev\2.4 will have a prefix of C:\core\guidewire\Dev\2.4. Git source for the current version shows no sign of case-insensitivity, so the msys fork may have modified the path-checking function, or case-smashed all paths prior to comparison.

GitBucket: error: Your local changes to the following files would be overwritten by merge

I have searched everywhere and tried various solutions but am still getting the error:
Your local changes to the following files would be overwritten by merge
i have nothing to commit as status tells me the following:
# On branch develop
# Your branch is behind 'origin/develop' by 1 commit, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
nothing to commit, working directory clean
So then I do a git pull, then get the following:
Updating 67020e6..6dd23de
error: Your local changes to the following files would be overwritten by merge:
app/filename.php
Please, commit your changes or stash them before you can merge.
Aborting
But as I have nothing to commit and if I do a git stash I get No local changes to save
So how can I fix the problem and download and update my local machine with my remote amends.
Bit of history incase:
I have to local machines one at home and work I have done the amends at home and pushed them and I am now trying to update my local work machine with these updates.
EDIT UPDATE
As I cannot answer my own question for a while I found what for me solved this answer:
on the branch I wrote:
git reset --hard
Then the pull worked.
While looking around i tried the following that seemed to fix my issue at the time.
While on the branch i wrote.
git reset --hard
Had you ever previously done git update-index --assume-unchanged <file>? That could be a potential reason for your situation.
To fix, you do git update-index --no-assume-unchanged <file>. Then you should be able to stash your changes and continue with the merge.
Faced exactly the same problem. I was used to CVS before I started exploring git. I think running git pull --rebase origin master is the way to go for the kind of workflow that you and I use.
Refer to https://www.atlassian.com/git/workflows#!workflow-centralized for a more detailed explanation. I definitely know the answer is somewhere in that article, but I didn't understand the article completely.

Resources