0

I just started using git in Windows. I am using the latest PortableGit version 2.30.1 and I believe I have set them up correctly.

I am just trying to practice with git's more advanced features such as branching, merging, tagging etc. So I created a simple mock project for it.

I just started the project. The project has only 2 files currently: f1.py and .gitignore. It currently only has 2 commits.

The problem is that in my last (2nd) commit, I have incorrectly use single quote for git commit message and it complains of pathspec error:

C:\ex\gitpractice>git commit -m 'Modified A1 -> A2'
error: pathspec 'A1' did not match any file<s> know to git
error: pathspec '-' did not match any file<s> know to git

Then I tried:

C:\ex\gitpractice>git commit -m \'Modified A1 \-> A2'
fatal: \A1: '\A1' is outside repository at 'C:/ex/gitpractice'

Which resulted in something 'fatal', I know, I was so stupid... Then I commited using the correct double-quote:

C:\ex\gitpractice>git commit -m "Modified A1 -> A2"

It was successfull. But anyway, I was left with multiple files, that I did not intentionally create. Anyway here is the screenshot of what has happened:

git commit using single quote and the results

As you could see, I tried removing the other files using git rm and it did not even work. I also used Vim 8.2 to edit the files there (and I am just a beginner vim user). And I just knew today that I should not be using single quotes in git-cmd.exe in windows from https://github.com/cmderdev/cmder/issues/2052. But I was still left with the extra files created.

What happened during the 'fatal' commit? What are those extra files? Is it safe to remove them? Should / How can I remove them ? (I usually used git and edited in nano in Ubuntu machines before)

tek27
  • 43
  • 1
  • 4
  • You cannot use `git rm` if the files are not in the index. Just use `del ` (if I remember well) to delete them. – Marco Luzzara Feb 24 '21 at 10:26
  • I think the question ended up not actually being about git (as the tag suggest) , but more on how to delete weird-named files in Windows – Ivan Feb 24 '21 at 10:28
  • delete weird file names on windows in git-bash. Simplest solution is probably to just use Explorer :). – jessehouwing Feb 24 '21 at 10:31
  • what re those files that ends with the ~ (tilde)? Is it vim related? But I had closed vim already, why is it still there? And is it safe to just delete them? – tek27 Feb 24 '21 at 10:48
  • Note: it's just plain `cmd.exe`, which is (based on) the old MS-DOS command line interpreter and comes with Windows systems. It's not a very good command line interpreter. I don't use Windows but a lot of Windows programmers seem to like Powershell, which apparently is well integrated with Windows. As a Unix/Linux programmer I prefer sh or bash; there's a port of bash to Windows as well. Some versions of it are included with some Windows Git distributions. – torek Feb 24 '21 at 10:48
  • 1
    Note also that bash has nothing to do with Git (though some Git programs are written as scripts that require a POSIX-compatible shell, and bash is sufficient to run those scripts). The file names ending with tilde characters are some editor's backup versions. `vim` and `emacs` can both be set up to do this; probably other editors can be as well. See, e.g., [this question](https://stackoverflow.com/q/607435/1256452). This too has nothing to do with Git itself. – torek Feb 24 '21 at 10:50
  • @torek ok, yes they (*~) are vim files. I tried adding `set nobackup` to `C:\Program Files\Vim\_vimrc`, but I can't save, it's a read-only file. How can I add the `set nobackup` to the _vimrc ? – tek27 Feb 26 '21 at 06:53
  • nvm. I figured it out : https://stackoverflow.com/questions/30276164/how-to-edit-vimrc-file and https://stackoverflow.com/questions/15660669/what-is-a-un-file-or-or-why-does-vim-in-the-terminal-make-the-un-file – tek27 Feb 26 '21 at 07:03

2 Answers2

1

Basically you executed command > file. > redirects the output of a command into a (new or existing) file. This works similar to the IO redirect operator in Linux shells.

Git didn't do anything, your shell did. In other words: the file is not tracked by Git, that's why you cannot git rm it ("pathspec" is Git language). Simply remove the (untracked) files with Windows Explorer or from cmd.exe:

del A2'

or

del A2*
knittl
  • 246,190
  • 53
  • 318
  • 364
  • 1
    Yes, you are correct. But `rm A2'` will only work in powershell, not in cmd.exe. I used `del A2'` in cmd.exe – tek27 Feb 26 '21 at 07:33
  • @tek27 right, I missed that bit. Updated my answer to recommend `del` for cmd – knittl Feb 26 '21 at 17:47
0

Looks like you're using the fancy-single quote , not the simple one '. Not sure what causes that, but you shouldn't be using fancy quotes. Windows uses double quotes to create long string arguments.

From the standard windows command prompt, I can type

> del A<tab>

And the prompt will auto complete to the correct format to delete (> for cmd and $ for git-bash):

# For the ' version
> del "A'"
$ rm A\'

# For the ’ version
> del A’
$ rm A’

git rm can't delete these files, because they aren't staged yet. So, git can't find the file in its index. And can't delete it. The error message is a bit misleading. The pathspec didn't match any files git is aware of.

Why were these created? Well, the > character puts the output into a file with the name behind it. And the ' and characters don't create an escaped string. Only " does.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • 1
    I don't think the OP had a Microsoft-style smart-quote inflicted on his command: it's just that the old CMD.EXE shell simply doesn't have single quote as a quoting character, so that `-m 'this that'` means the equivalent of a sane shell's `-m "'this" "that'"`. – torek Feb 24 '21 at 10:56