Cannot remove git repository completely - windows

I have been using git on windows-msysgit. Whenever I try to remove a repository completely either using explorer or using
$ git rm -rf ptp/
fatal: Not a git repository (or any of the parent directories): .git
it errors out "The data present in the reparse point buffer is invalid" or the fatal error above.
What's wrong with me/git?
Thanks in advance

To remove a git repo, just do rm -rf ptp/. That's it.
git rm is used to move items from the index [the staging area for changes / new files], not to delete git repositories.

To get rid of the git repository on Windows do this:
Win+R, Type cmd, Enter.
> cd c:/path/to/parent/of/ptp-repo
> rmdir /S /Q ptp
Or if it fails then check who locks the directory and delete it by hands from Explore.
Most likely some process holds a lock on files/dirs in your repo.

I tried to remove GIT on my windows-XP, by means of the Windows/Configuration/Software menu. After some error message (which I cannot remember), it removed all files. I checked it, and there are no files with ptp in the name left on the entire system.
A problem remained however: each time I opened windows-explorer, a nasty error message came calling for a dll file that wasn't there anymore.
When checking the registry, there were many traces to GIT left in the registry. I removed them carefully by hand, which seems to have solved the problem. This is of course a dangerous path, but I had no choice. Perhaps it is a good idea to look into the Windows-deinstallation script very carefully.
Stef Joosten

On Windows 10, try running cygwin console as admin and rm -rf the dir.

I have also just experienced this odd problem on windows 10: An empty .git folder simply would not delete and a restart of windows did not remedy it, nor did rmdir .git, nor did rm -rf .git.
Similarly to another suggestion, I used ubuntu (instead of cygwin) for windows (https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0) and issued an rm -rf .git, that worked perfectly

This solution should make it possible to delete any locked files and folders without installing any new programs:
Go to your Resource Monitor (in the Task Manager)
Go to the CPU tab
Search for your file in the "Associated Handles"
Now you'll see which process(es) are locking your file (it's likely explorer.exe)
Close those processes (be careful, this might delete unsaved work)
Delete your previously locked files, this should work without a problem now.
Optional: Start processes again (for explorer.exe: Go to Task Manager, File → New task → type in "explorer.exe")

This should work:
On Git Bash do:
$ git remote remove <name>
To see your remote list:
$ git remote

When I want to remove a GIT repo on Windows... i very simply delete (or move) the .git directory where the repo sits... I do this straight from Explorer... it hasn't failed me yet!

I have a third partition, on a dual boot with Windows 7 and Fedora Linux, and I realized I had a file open in vim in a terminal, and that was causing a .fuse_hidden... file to not be deletable.
When I closed the file in vim, I was able to delete the .git directory.

Related

Can't commit - '.git/index.lock': File exists. Even though, there is no file like that

Getting an error when trying to commit and push:
Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue.
What I tried:
finding that file and deleting it - there is no file index.lock in this repo. It is not there, neither in the .git folder nor in git/refs/head/my_branch (yes, hidden files are shown, yes I tried through sudo).
completely delete the repo and clone it once again, and then committing.
kill all of the git processes.
hard reset of computer.
rm .git/COMMIT_EDITMSG - no such file
No result.
the error has nothing to do with the real cause of the problem. Spend time "fighting" with what I am not suppose to "fight" at all, lol.
I did ga . & gcmsg "updated" && gp instead of ga . && gcmsg "updated" && gp 🤣
Maybe will be helpful for someone.

Windows 7 - undeletable file after git conflict

I recently had a git conflict, and rather than dealing with it properly, I didn't actually fix any of the conflicts, but did something like overwrite the files with another version from another clone of the repo, or moved the files out of the directory, or did a git reset --soft, or some other convoluted series of commands.
Anyway, I've been left with some files on my filesystem that I cannot delete. I cannot move them, rename them, delete them with DEL in the command line, or with RM in gitbash. The file is named:
pom.xml~9b19d48... dpom_refactor
It has 0 bytes, and I've no clue how to get rid of it. I no longer have any .git folder, so I can't use any git commands to rollback what I did. Whenever I attempt to delete/move/rename, I get the error:
Could not find this item
This is no longer located in C:\<filePath>. Verify the item's location and try again.
Any thoughts on how I could get rid of it?
This kind of invalid Windows filename could be dealt with like a nul file.
C:\> rename \\.\C:\..\pom.xml~9b19d48... dpom_refactor del.txt
C:\> del del.txt
Using the \\.\ prefix tells the high-level file I/O functions to pass the filename unparsed to the device driver
If that was to fail, only a dedicated tool (or Live Linux distro CD) would be able to mount that disk and remove the file.

Git: rename directory (case-only) on Windows

I want to rename a directory versioned by Git on a Windows system (change the case of the directory name):
$ git mv docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied
I've also tried with the force-option - but with the same result:
$ git mv --force docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied
For some reason Git fails because it thinks DOCS already is an existing directory and the directory should be moved inside it. I know that I can rename & commit using a temporary directory name and then rename & amend-commit to the final name, but isn't there a way to tell Git that I don't want to move inside any other directory?
You can try to do it in 2 step.
$ git mv docs DOCS2
$ git mv DOCS2 DOCS
it will work
I have tried to rename my directory with TortoiseGit using rename, command prompt using git mv, and git bash using git mv. The move command was either mv Status status or git mv Status status2 and both of them respond "failed: Permission denied". So it seems I am either going to have to delete the git repository and create a new one with the new directory name structure or I am going to have to create a Linux VM, clone it down, and try to rename name it there. It seems only files can be renamed under windows, but directories just fail. As for people that say git mv works for them, there has to be something missing in your setup.
Since windows iד case sensitive you cant rename the file to the same letters. (Docs == docs [ignored case])
You can do it from git bash since git bash is cygwin and its case sensitive since its a unix emulator.
The command is git mv
git mv <old name> <new name>
Here is a demo from git bash. (windows 7)
No. There isn't a way to tell Git that you don't want to move the folder inside any other directory.
This is not a limitation of git, but rather a limitation of Windows and NTFS. Because the filesystem is case-insensitive, it reports that the case-changed new name already exists, which causes the behaviour that you encounter. Try a 2 step rename (with a temporary name), then commit, or changing it on a non-windows (technically on a case-sensitive filesytem) computer.

Git for Windows -- Git Bash Here... -- creates .git/config

I am using Git for Windows 2.5.1 under Windows 7 x64.
I am experiencing a strange phenomenon, that is...
...whenever I use Right-Click / Git Bash Here... on a plain directory that is not under the control of git (i.e. there is no .git directory present), a new subdirectory .git gets automatically created (with a file "config" in it), however, no git command has been issued.
I went into my registry settings and I found that the "Git Bash Here..." shortcut translates into "git-bash.exe" "--cd %v".
My question is as follows: is there any way to tell "git-bash.exe" * NOT * to create any .git folder (at least not as long as no git command is issued)
The problem is that I use "Git Bash Here..." all over the place, even for directories that are not under the control of git, and what happens is that my harddisk is now littered with many empty, useless .git directories.
I was thinking, maybe there is an additional option to prevent the creation of .git/config ?
Maybe git-bash.exe --cd %v --do-not-create-git-config ?
Any ideas ?
Thanks for #poke's comment
In fact, in my ".bashrc" I had a left-over from last week's testing: "git config color.diff auto"
I had forgotten to remove that line.
When I remove the "git config color.diff auto", everything goes back to normal
Problem solved

Git-bash tab completion: "fatal: Not a git repository: '.git'" (Windows)

I'm using git on windows with the git bash and every time I want to autocomplete a filename in a git command I get fatal: Not a git repository: '.git' posted between my already typed characters and the completed ones.
It looks like this:
$ git diff a
<using tab>
$ git diff afatal: Not a git repository: '.git'
pp.js
I can still make the command properly by just pressing enter as expected. But it really starts to get on my nerves.
Any suggestions?
The problem was an extra .git-folder in my src folder. The repository was initialized on the folder above (src/..) and this seemed to mess with git. After the removal of the extra .git folder the problem disappered.
I just discoverd the solution. I had an extra .git directory in my src-folder which seemed to mess with git (the repository was initialised on the folder above).
After I removed the extra .git folder the problem disappered.
It can depends on the msysgit version you are using:
I just tested a tab completion on a git diff on W7 64bits, with the latest msysgit1.8.3, and it worked just fine.
Don't forget that, in addition to the msysgit version, you will have issues with tab completion due to the old bash 3.1 included in mysysgit.
And the completion can be slow on Windows.
As the OP Zeeker mentions below, the completion git-completion.bash is based on a proper git repo path detection.
# __gitdir accepts 0 or 1 arguments (i.e., location)
# returns location of .git repo
__gitdir () {
...
}
And in Zeeker's case, an extra .git folder was in the src folder, which means any completion was based from the wrong folder, which, for git diff, proved fatal.
git add seems to work though.
git-bash completion for git commands is controlled by the /etc/git-completion.bash. To fix run git-bash as administrator, then:
cd /etc
mv /etc/git-completion.bash /etc/git-completion.bash.orig
Then create a new one from the contents of https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

Resources