1

Assume I am one of many developers working with git on a huge code project, which has an incredibly long compilation time.

Now, my personal day-to-day changes are usually limited, and the codebase is decently modular, which means that as far as my personal work is concerned, compiling from scratch is a price that only has to be paid once. Afterwards, I can recompile only the modules I modified.

On the other hand, I frequently have to fix bugs in (at least two) branches which reflect states of the codebase completely distinct from the branch I work on. Those two branches are indeed the result of work from the entire development team, and often have entire modules rewritten or added. Having compiled everything before pushing a bugfix is mandatory.

My first approach was to switch from my development branch every time a bugfix is needed, then clean, bugfix, recompile from scratch, push, switch back to the original branch, clean again, recompile - the delay for doing this is intolerable.

I then moved to keeping three separate checkouts of the codebase on my machine. This solves the "costly recompilation" problem (my changes in every branch are incremental again), but it makes the question "what am I developing on right now ?" more complex to answer (since it depends on the current directory), and it makes synchronization of these three copies complex (it multiplies all the routine push/remote update/pull commands I have to do by three).

A simpler solution would be to have the ability to save the state of a directory (untracked, where I generate compiled files) every time my checkout "leaves"a branch, and to recall the state of that directory, if it exists, every time I "enter" (checkout) a branch.

  • Are there git commands that would help me achieve this behavior ?
  • If not, is there a tool that would allow me to do that ?
  • If not, does git provide checkout hooks that could help me script this behavior ?
Francois G
  • 11,957
  • 54
  • 59
  • 2
    A not so elegant solution is to append, for example, the branch name, to the compilation output folder, and rename it back when you are working on that branch. – nhahtdh Jun 12 '12 at 09:46
  • @nhahtdh: I think that's the most elegant solution as long as all those folders are inside a common folder so you don't clutter the root source folder with those folders. – ThiefMaster Jun 12 '12 at 10:14

3 Answers3

1

I would suggest to use stashes, they are pretty close to what you need.

In recent versions of git, you can stash untracked files with the --include-untracked option. You can also give messages to your stashes and recall them, so you can check in which stash must be applied after checking out a branch.

#before leaving branch
git stash save --include-untracked "compiled stuff for my_branch"
git checkout another_branch
#what stash contains compiled stuff for another_branch?
git stash list
git stash pop stash@{n}

You can script a bit to make things more practical...

CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • Thanks a lot ! very good suggestion ! I think you have to put the `--include-untracked` *after* the `save` command though. – Francois G Jun 12 '12 at 12:29
0

I'm afraid I do not have exact answers as I did not have to deal with a case like yours, but anyway I'd like to provide possible hint: Git is able to use several distinct work trees "connected" to a single repository (read more in this answer for instance), so instead of maintaining multiple checkouts, you can just use multiple work trees with a single repository.

I should add that I like @CharlesB's solution better (conceptually) but on the other hand I would measure: supposedly git stash would effectively copy your files when turning them into blobs to store in the stash which would a) temporarily double the space occupied by those huge files on the filesystem; b) have unknown long-standing effect on the size of the Git's object database size.

Community
  • 1
  • 1
kostix
  • 51,517
  • 14
  • 93
  • 176
0

My 2 cents : keep track of the compilation directory as a submodule - but as I haven't used this git feature yet, I can only point you to the doc page...

LeGEC
  • 46,477
  • 5
  • 57
  • 104