I cannot cd into some of my .git directories on Windows.
Some of my repositories are fine. The .git directory appears as you would expect in them:
drwxrwx---+ 1 grandps Domain Users 0 Oct 11 15:42 .git
I can cd into the .git directory, and ls it to see its contents.
In other repos, the .git directory shows up as a regular file. I can't cd into it or ls to see its contents. If I try to open it in Windows Explorer, I can't - Windows thinks it's a file, too.
-rwxrwx---+ 1 grandps Domain Users 68 Jun 22 12:22 .git
The repo still works as a git repository. I can run git commands just fine. I just can't get into the .git folder.
I have tried both Git Bash (MinGW64) and Cygwin. Both give the same results.
Any ideas how this could have happened, and how I can fix it?
According to documentation, the file should contain path to the actual repository directory.
Also you can have a plain text file .git at the root of your working tree, containing gitdir: to point at the real directory that has the repository. This mechanism is often used for a working tree of a submodule checkout, to allow you in the containing superproject to git checkout a branch that does not have the submodule
source: https://git-scm.com/docs/gitrepository-layout
Related
I want to put my LARAVEL project from the git repository to my server, to do this I:
git init
sudo git clone git#gitlab.com:test-name/my-project.git
Now I have the following content:
drwxr-sr-x 4 ubuntu www-data 37 Mar 26 08:53 ./
drwxr-xr-x 6 root root 101 Sep 5 2019 ../
drwxr-sr-x 7 root www-data 119 Mar 26 08:53 .git/
drwxr-sr-x 12 root www-data 4096 Mar 26 08:53 my-project/
and now when I list my-project I also see .git\ directory !
But in fact I want the content of my-project directly, not inside my-project directory.
What should I do ?
Don't bother with the git init at all: git clone means:
Make a directory, and enter that directory, so that all of the remaining five steps occur in that directory.
Run git init.
Run git remote add origin url, where the url comes from the git clone argument. You can change this name from origin to some other name, but you didn't.
Run any necessary git config operations (you didn't list any extra configurations to apply so this step doesn't do anything in your case).
Run git fetch origin.
Run git checkout name, where the name comes from the -b argument you gave to git clone. You didn't give one, so instead, name comes from the recommendation that the other Git over at origin gives. Most other Gits recommend master.
Note that step 2 does its own git init, so that's why you should not be doing one yourself. (If you like, you can run all six steps yourself, one at a time. Note that if you do that, you'll wind up in the directory you made. When git clone makes the directory and enters it, that doesn't move you, so this is slightly different.)
(In general, you should not be running any Git command with sudo. You might have some particular reason for doing that, but in general you should find some way to avoid doing that.)
I have the same problem as this one but I'm on Windows.
I searched everywhere to fint a .git (not only in Windows) but nothing.
Not even in projects where I did git init (via the terminal of VS code).
I suppose that's why I get this error. Because all the projects where I use git, use the same .git file that is somewhere...
When I run (in a project) git rev-parse --show-toplevel to find out where my git repository root is, I get C:/Users/username. Which is of course wrong! But in there (as you see in pic) there is no .git file. Should I delete gitconfig?
How can I find the .git that creates the problem?
Why my projects that I've used git init don't have a .git file?
Go to Control Panel -> File Explorer Options
Select the "View" Tab
Select the following options:
Check: Show Hidden files, folders and drives
Uncheck: Hide extensions for known file types
Check: Show drive letters
Check: Show encrypted or compressed NTFS files in colour
Check: Navigation Pane/ Expand to open folder
Check: Navigation Pane/ Show all folders
You should now see the .git folder, and delete or rename it.
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.
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.
I've got a series of HTML pages and other files for a website hosted on heroku sitting under a folder named 'sitename' on the User level of my computer - Windows 8 64 bit (that is, the files are in 'C:\Users\Me\sitename'
I'm trying to deploy them to the site using this code:
$ git add .
$ git commit -am "make it better"
$ git push heroku master
When I execute '$ git add .', the console starts returning tons of messages naming certain files and saying 'The file will have its original line endings in your working directory. warning: LF will be replaced by CLRF'.
Reading the question here, I found that it probably wouldn't affect anything in my code. However, when I run the code, it doesn't just affect the files in my git repository (which I think is set up correctly by running '$ git init', which creates a .git folder on the same level as the sitename folder), but starts to affect files in my AppData folder, e.g. iTunes.
Is this expected behavior? Will it affect anything? And is there a way to direct 'git add' towards only the repository?
I would recommend investigating where your git folder really is for your project first. Because it seems like you have somehow added files from the Appdata folder to your project, this indicates that the git folder you have created is not seperated from the other folders on the server. For example you have your git folder in:
'C:\Users\Me' instead of 'C:\Users\Me\sitename'
To easily see what files that have been added to your git project/Hasn't been added you can execute the command:
git status
This will also show your current staged files and if you have commited something.
To add single files/folder just write:
git add example.html
Where example is the name of the file you want to add (it can be any extension).
To remove files just do the same but use git rm.