Home > Back-end >  how to remove '/' slash from folder name inside repository in github?
how to remove '/' slash from folder name inside repository in github?

Time:10-12

I am adding a file inside a folder's folder. after adding the file, when I see the repository, it is showing me a slash. how to remove that?

how to remove / slash from folder name ?

CodePudding user response:

That slash isn't anything. The github is just specifying where the update happened. If you look closely you can see that "Food/" is grey while "Fruit" is black.

TL;DR : there's nothing to remove

CodePudding user response:

The slash is an illusion. In fact, folders in general in Git are an illusion. Git doesn't store folders in the first place.1 What Git stores are commits, and what commits store are files and metadata.

Files, in Git, have long names that contain embedded (forward) slashes, such as classes/science.ext, food/fruits/apple.ext, and new/welcome.png. If you check out a commit that has these three files in it and run:

git ls-files --stage

you'll see output like this:

100644 8f3f967230c9ec9a6386b37700891e0f648dc93f 0       classes/science.ext
100644 93df50769a3921e771b714fa1c9ee83f5483f016 0       food/fruits/apple.ext
100644 cc46fc918955220eea72d2fa5839909a41000712 0       new/welcome.png

(the hash IDs in column 2 will be different; I stole these hash IDs from a few files I had nearby).

This is what's in Git. Of course, for you to be able to work with these files—the ones inside Git are frozen: completely read-only, compressed, readable only by Git and writable by nothing, not even Git itself, once they've been frozen into place like this—Git has to copy those files out of the commit, into a work area. This work area lives on your computer ("your laptop", or a server, or whatever), in the usual format that your OS uses to store files, which is probably folder-structured. So when you clone a repository and extract a commit, you do get files-in-folders.

When GitHub or some other server site lets you browse through commits, they must fix up this mismatch: Git stores files with embedded forward slashes in their names, but what the user wants to see is a set of folders containing files. So GitHub do the same thing Git does: dynamically pretend that there are folders containing sub-folders containing files, and so on.

When GitHub discover a "folder" that contains just one "sub-folder", GitHub—not Git—choose to display that as food/fruits. That's not what's in the commit: the commit contains files named food/fruits/apple.ext or whatever. But rather than showing you a synthesized folder named food that, if you clicked on it, would next show you a synthesized folder named fruits that, if you clicked on it, would next show you the file apple.ext, GitHub choose to reduce the number of mouse-clicks required, by showing you a synthetic folder whose name is food/fruits.

Since this folded doesn't really exist anywhere—Git has to create food and food/fruits later, at the time you git checkout or git switch to the commit that contains the file food/fruits/apple.ext, so that your laptop is happy creating a file named apple.ext in a folder named fruits in a folder named food—it doesn't matter how the display works. All that matters is that you know that Git stores commits that then store files.

The GitHub display deliberately "peeks through" various commits to find which file(s) were most recently changed-or-added within some synthesized "folder" and puts that at the far right, giving you a display:

           
  • Related