1

I'm new to git and trying to use it with a project that has many (several hundreds) sources. The problem I have is that git is extracting all the project's sources to my working directory when doing checkout. This makes a lot of mess as I have to jump between the files and can unintentionally change/corrupt files that I wasn't even planning to change. I would prefer to extract only sources that I'm going to modify and then work with them. So, is there a way to tell git that I only going to work with specific sources, and so, that only these sources would be extracted to the working directory? Note, that this is not a partial checkout or something like this. I'm ok to checkout the whole branch. It's more about organising a working folder. Thanks.

spoonboy
  • 2,570
  • 5
  • 32
  • 56
  • 1
    This isn't clear; you only want to "extract" certain sources, yet you don't want a partial checkout? What is the distinction here? – Oliver Charlesworth Jun 08 '14 at 09:09
  • This means that I want to have the whole set of sources in the commit. – spoonboy Jun 08 '14 at 09:10
  • 2
    Also, one solution is to just not modify any files that you don't want to modify. And even if you do (accidentally), just use `git status` to see what you've done, and then use `git checkout` to revert accidental changes. – Oliver Charlesworth Jun 08 '14 at 09:10
  • Ok, my issue is with hundreds of files in my working directory. It's not how I prefer to work. I prefer to get only few files related to the change I'm doing in my working folder. – spoonboy Jun 08 '14 at 09:14
  • 3
    Then it sounds like the real problem is that you need to tidy up your repo (organise stuff into subfolders, etc.) – Oliver Charlesworth Jun 08 '14 at 09:15
  • Well, it's not always possible to isolate your changes in folder. It's quite usual when let's say you change parameters for some commonly used procedure and then need to checkout all the sources that are using it to make the correspondent changes. – spoonboy Jun 08 '14 at 09:21
  • I'm not talking about isolating your changes; I'm referring to your comment that you end up with "hundreds of files in your working directory" - if that's the case, then you should reorganise them. – Oliver Charlesworth Jun 08 '14 at 09:24
  • 1
    You *could* have a full repository checkout and a totally separate working folder with hard or soft links to some subset of the files. But you're probably better off just having the files organised sensibly in the first place (so it becomes easy to find the files you're interested in even if there are lots of files), as Oli is suggesting. – Matthew Strawbridge Jun 08 '14 at 09:29
  • 1
    It might be worth mentioning that having only some of the project's files available will complicate any assistance tools your IDE might have - IntelliSense, static analysis, automatic renaming/refactoring... – DCoder Jun 08 '14 at 09:29
  • Thanks, Oli, I understand this. But my point is that even organising sources into a structure of folders will not make it easier. Actually, it will make it even worse, as I'll have to jump between different subfolders all the time. I would prefer to do this task once when selecting sources that I'm going to modify and then get them ( and only them) easily accessible in one working directory – spoonboy Jun 08 '14 at 09:34
  • @spoonboy: So you *are* asking about a partial checkout? Even so, I don't see how this would be helpful. If you need to do widespread refactoring, what you're asking for would require calculating beforehand all the files you need to modify. How is that easier than just checking out everything? – Oliver Charlesworth Jun 08 '14 at 09:37
  • Did you check the meaning of .gitignore? – Emiliano Poggi Jun 08 '14 at 11:02
  • @spoonboy I have edited my answer below to add another alternative, as an illustration of how your issue could be addressed. – VonC Jun 08 '14 at 11:05

1 Answers1

2

If your relevant sources are all in a specific subfolder, you can do a sparse checkout, in order to checkout only that specific subfolder content (which you would declare in a .git/info/sparse-checkout file, as I mention here).

If not, then you need to move them into folder (reorganization), or even isolate them into their own repo (and add them to the main repo as submodule)


The other alternative is to use an IDE which support task-based context filtering.
For instance Eclipse Mylyn, that I mention in "Eclipse - easy access to frequently used folders?".
Mylyn is a task-focused interface using context:

https://i.stack.imgur.com/A7Wnl.png

That might not be part of your stack, but it illustrates how that issue of getting "only few files related to the change I'm doing in my working folder" can be addressed.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Unfortunately, they are not. See my comment from above. – spoonboy Jun 08 '14 at 09:22
  • @spoonboy I have added an alternative, but there won't be any magic solution. Git manages content as a whole. – VonC Jun 08 '14 at 09:24
  • Ok, thanks, I think then the answer is No. just curious, does mercurial supports such extracts? – spoonboy Jun 08 '14 at 09:27
  • @spoonboy with the current organization of the repo, indeed: no. – VonC Jun 08 '14 at 09:27
  • @spoonboy not sure about Hg (Mercurial) and sparse checkout: http://mercurial.selenic.com/wiki/PartialClone and http://stackoverflow.com/a/2587100/6309 suggest "not possible". – VonC Jun 08 '14 at 10:55