-1

Assume this a structure of top most commit

  --src
      --app
         --node_modules
         --code

In older commit the code does not live inside app rather it lives inside work and there is no app folder. so when I checkout to that commit this will be my structure

   --src
       --app
          --node_modules
       --work
           --code

Since node_modules is a .gitignore directory. It wont be removed. As you can see when you have lot of directory like this there will be huge screen space taken by directory which we dont need.

My doubt is that is there any way I can remove those directory and add then add those when I want, in this case it will be when I am in topmost commit. Just like how git stash works?

Thanks for the help!

Nivekithan
  • 953
  • 1
  • 6
  • 10
  • You could `git clone` to some other directory before your `git checkout`. Disk space is cheap – Basile Starynkevitch Apr 18 '21 at 04:03
  • @BasileStarynkevitch isnt `git clone` just clones the repo. I am not really sure how this is helpfull – Nivekithan Apr 18 '21 at 04:15
  • Just have *two* copies of your git-ed repository in two different directories. – Basile Starynkevitch Apr 18 '21 at 04:18
  • @BasileStarynkevitch then I should remove those files manually? – Nivekithan Apr 18 '21 at 04:20
  • Did you spend hours in reading the [documentation of `git`](http://git-scm.com/doc) ? – Basile Starynkevitch Apr 18 '21 at 05:20
  • Can you explain your issue with these folders ? Do they take space on *disk* or in the output of *git status* ? – LeGEC Apr 18 '21 at 07:40
  • If you want to always ignore `node_modules` folders, you can add `node_modules` to one of the global ignore files. See https://stackoverflow.com/a/22906950/86072 – LeGEC Apr 18 '21 at 07:43
  • @LeGEC They too take up lot of spaces. But thats not my problem, my problem is purely convenience. In my repo I have almost 10 - 12 directory which contains its own node_modules. But in older commit, I grouped all of the code into a single directory and they shared single node_modules. So when I go back to older commit, those 10-12 directory are still present and taking up screen space. I dont want that, I could just delete all those directory manually but then when I go to top most commit, I have to download those node_modules again. Which are huge and takes lot of time. – Nivekithan Apr 18 '21 at 10:05
  • 1
    It's not at all clear to me what you really want here, but note that if you run `git stash -a`, this *commits* the untracked-and-ignored files, then uses `git clean` to remove them (now that they are safely committed). This does not save much disk space at all (in practice it may need *more* space temporarily as soon as the files get unpacked later) and these three-commit stashes are hard to use, but that will get them removed from your working tree. – torek Apr 18 '21 at 10:28
  • 1
    I think I understood your issue. The word "space" in your question is misleading, since most readers will understand "disk space" : could you rephrase that sentence, to better explain your issue ? (`ls` will still list all directories, your visual file explorer will display them ... ) – LeGEC Apr 19 '21 at 09:46

1 Answers1

0

Assume you have a git repository like https://github.com/RefPerSys/RefPerSys (for the RefPerSys project)

You could do (on Linux)

git clone  https://github.com/RefPerSys/RefPerSys ~/RefPerSys_blue

then

git clone  https://github.com/RefPerSys/RefPerSys ~/RefPerSys_red

and now you have two copies of the same repository, one in directory ~/RefPerSys_blue/ and another in directory ~/RefPerSys_red/ both inside your home directory ~/

Later, you might

 cd ~/RefPerSys_red/
 git checkout 1b783efb1d17

and have, in ~/RefPerSys_red/, the commit 1b783efb1d17

Disk space is cheap, your time is less cheap.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • thanks for the reply but thats not the solution I need, so i thought my question might not be clear, so I edited it – Nivekithan Apr 18 '21 at 04:45
  • Why are you forbidden to have two copies of your repository on your hard disk? This should be written in your question! – Basile Starynkevitch Apr 18 '21 at 05:13
  • I am not forbidden from having two copies of same repository, but how having two repository is going to solve my problem ?, having two repository wont remove the `node_modules` directory – Nivekithan Apr 18 '21 at 06:10
  • 1
    @Nivekithan: waht this answer suggest is : check the older version of your repo in the second clone, if you manipulate only the older version in that clone, its layout on disk will match what you expect. – LeGEC Apr 19 '21 at 09:43