Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git and C++ workflow, how to handle object and archive files?

Tags:

c++

git

workflow

I use git to interface with an SVN repository. I have several git branches for the different projects I work on.

Now, whenever I switch from one branch to another using 'git checkout ', all the compiled executables and object files from the previous branch are still there. What I would like to see is that switching from branch A to B results in a tree with all object files and binaries from the last time I worked on branch B.

Is there a way to handle this without creating multiple git repositories?

Update: I understand that executables and binaries should not end up in the repository. I'm a bit disappointed in the fact that all the branching stuff in git is useless to me, as it turns out I'll have to clone my proxy git repository for every branch I want to start. Something I already did for SVN and hoped to avoid with git. Of course, I don't have to do it, but it would result in me doing a new make most of the time after switching between branches (not fun).

like image 206
Ton van den Heuvel Avatar asked Mar 17 '09 17:03

Ton van den Heuvel


People also ask

Can git be used in a centralized workflow?

Centralized Git workflowA centralized Git workflow enables all team members to make changes directly to the main branch, with every change logged in a running history. A centralized workflow involves every contributor committing to the main branch without using any other branch.

How does git archive work?

Git archive is a helpful utility for creating distributable packages of git repositories. Git archive can target specific refs of a repository and only package the contents of that ref. Git archive has several output formats that can utilize added compression.

What is the first step in a typical Git workflow?

The first step is to stage the changes to commit using the git add command. You can add multiple files at a single time, separating their name by space. The last step is to commit the changes using the git commit command. Please remember to give a descriptive message to your commit.


1 Answers

What you want is a full context, not just the branch... which is generally out of scope for a version control tool. The best way to do that is to use multiple repositories.

Don't worry about the inefficiency of that though... Make your second repository a clone of the first. Git will automatically use links to avoid having multiple copies on disk.

Here's a hack to give you want you want

Since you have separate obj directories, you could modify your Makefiles to make the base location dynamic using something like this:

OBJBASE = `git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1\//'`
OBJDIR = "$(OBJBASE).obj"
# branch master: OBJBASE == "master/", OBJDIR == "master/.obj"
# non-git checkout: OBJBASE == "", OBJDIR == ".obj"

That will but your branch name into OBJBASE, which you can use to build your actual objdir location from. I'll leave it to you to modify it to fit your environment and make it friendly to non-git users of your Makefiles.

like image 92
Ryan Graham Avatar answered Sep 20 '22 14:09

Ryan Graham