1

I'm forced to create some folders with tildes in their name. Like, ~144455502343~. I cannot check these into git.

This answer came up, but it does nothing. I'm on a Mac so the NTFS thing shouldn't affect me.

I'm using git version 2.11.0

Unable to add files with name containing tilde, '~' followed by a number

Anyone know what to do to check in folders containing tildes?

// edit

I mean I cannot add them. The folders are ignored completely. They are not in my .gitignore but they also do not show up when doing git status, git add \~144455502343\~.

// edit

Looking for the spot where this is ignored.

Jorg
  • 7,219
  • 3
  • 44
  • 65
  • `cannot check` ? do you mean you cannot add/remove/do anything in git with these files ? `\\` works fine on linux ( and i assume mac is similar ) – Priyesh Kumar May 23 '17 at 08:07
  • 1
    Hi, have you tried `git add \~144455502343~` – crea1 May 23 '17 at 08:07
  • @PriyeshKumar yes, I cannot add these. – Jorg May 23 '17 at 08:07
  • 1
    What do you mean by "I cannot add"? Is Git displaying an error message? What is its output? What's the output of `git status`? – axiac May 23 '17 at 08:08
  • I mean it's literally ignored, everywhere. – Jorg May 23 '17 at 08:09
  • Added pictures. – Jorg May 23 '17 at 08:15
  • Your `git add` seems to have worked. The fact that there's nothing in `git status` would just indicate that the file you copied from work-tree to index by `git add`ing matches the version of the file that is in the `HEAD` commit. Try `git ls-tree -r HEAD` to see precisely what's in `HEAD`, or `git ls-files --stage` to see what's in the index now. – torek May 23 '17 at 08:31
  • @torek as per `git status --ignored` I see them have a stray ignore file somewhere... trying to track it down – Jorg May 23 '17 at 08:36
  • @Jorg: normally if some file is ignored and you pass the name directly to `git add` you see a complaint: `git add git-worktree
    The following paths are ignored by one of your .gitignore files:
    git-worktree
    Use -f if you really want to add them.` (StackOverflow will eat the line breaks here, so I replaced them with `
    ` for display)
    – torek May 23 '17 at 08:38
  • @torek trying to find that file. The guys on the answer below have been helpful so far, but I haven't found it – Jorg May 23 '17 at 08:58
  • @torek if the folder `foo/` is ignored, you only get a warning if you try to add `foo`. If you try to add `foo/` you interstingly do not get the warning. Might be a bug though. – Vampire May 23 '17 at 09:09
  • What do you mean by "I cannot add these"? Is there an error? If you're trying to add a file that's ignored, you should get a message about that. If you're adding a directory and it's simply not picking it up, it's likely that it's being silently skipped--which is exactly how ignores should work. It's pretty common to ignore things with leading tildes (~) since Emacs uses it for backup files. I'd check your config and make sure you aren't ignoring all files with leading tildes. – John Szakmeister May 23 '17 at 09:28

2 Answers2

2

If you run git add \~144455502343\~/ and nothing happens, it is likely ignored.

If you run git add \~144455502343\~ and the folder is ignored, you will be hinted that the path is ignored.

To find out what pattern where ignores this, use git check-ignore -v \~144455502343\~ which will show you the exact file, line and pattern that ignores this path.

I guess you have something like *~ somewhere, as some text editors name backup files like that.

If this is the case and you want to keep the pattern, just use git add -f ... to force adding the file despite the ignoring. As soon as it is added, .gitignore is non-effective.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • It's this, although I have not found the ignore that checks the `~`. I have learned a bit about git though. – Jorg May 27 '17 at 04:52
  • Why didn't you? `check-ignore` tells you exactly. – Vampire May 27 '17 at 10:00
  • I've tried this in the comments of the other answer but I get no results for any variation of `git check-ignore -v "*~"`, the path to the folder directly or the entry listed in `git status --ignored`. – Jorg May 29 '17 at 04:15
1

You need to escape the tilde characters as follows:

git add \~144455502343\~
Peter Reid
  • 5,139
  • 2
  • 37
  • 33
  • 2
    My local testing proves otherwise (Mac). Do these directories contain files? You cannot add an empty directory in git. – Peter Reid May 23 '17 at 08:10
  • I know, I added some screenshots. The folder is not empty, `git add` gives no feedback, and the folder is not added. `git status` tells me it's up to date and the folder is not already in the repo – Jorg May 23 '17 at 08:17
  • 3
    @Jorg How about `git status --ignored`, in case the folder is ignored by some other gitignore configuration? – ElpieKay May 23 '17 at 08:20
  • My guess is that you are ignoring `*~` somewhere, since these are editor backup files. – Paul R May 23 '17 at 08:21
  • 1
    @ElpieKay Now we're getting somewhere... it's in there. It's not in my local `.gitignore`. Where can I find the global one? – Jorg May 23 '17 at 08:23
  • @Jorg Check `git config --global -l`, and see if you have `core.excludesfile` defined – crea1 May 23 '17 at 08:25
  • 1
    @Jorg check the content of `.git/info/exclude`, the value of `core.excludesFile` in `git config --list`, the content of `~/.config/git/ignore`. – ElpieKay May 23 '17 at 08:26
  • 1
    Run `git check-ignore -v \~144455502343\~` it should give a helpful debug output to show why the file name is ignored – Peter Reid May 23 '17 at 08:29
  • @ElpieKay wow, nothing. a commented out mention of `~*` in `.git/info/exclude`. I have no `core.excludesFile` set and `~` does not appear in `~/.config/git/ignore`. I'll check if homebrew left any traces anywhere. – Jorg May 23 '17 at 08:30
  • @Jorg You could also just use `git add -f` which allows adding of ignored files. – crea1 May 23 '17 at 08:32
  • @crea1 yes I guess I might have to run with that.I prefer not. – Jorg May 23 '17 at 08:33
  • @Jorg Just found this command `git check-ignore -v "*~"`. It should print out which ignore file the rule is located in. – crea1 May 23 '17 at 08:36
  • @crea1 no results. – Jorg May 23 '17 at 08:37
  • As @Peter and @crea1 suggested, you could try `git check-ignore -v *` before `git add -f` to list all the ignored files and where the configuration is defined. – ElpieKay May 23 '17 at 08:38
  • The output is `.gitignore:6:node_modules node_modules` and nothing else. – Jorg May 23 '17 at 08:40
  • @Jorg have you run `git add -f`? If yes, remove them from the index first by `git rm -r --cached ~144455502343~`. – ElpieKay May 23 '17 at 08:42
  • ironically, the new git client removed them for me. so, there are no files added from that folder (or: `did not match any files`). – Jorg May 23 '17 at 08:43