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

前端 未结 8 1822
鱼传尺愫
鱼传尺愫 2021-02-05 20:40

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

相关标签:
8条回答
  • 2021-02-05 21:07

    A make clean should not be necessary because files that are different between different branches get checked out with the actual date!!!

    This means that if your Makefile is correct, only those object-files, libs and executables are compiled again that really changed because of the checkout. Which is exactly the reason a makefile is there in the first place.

    The exception is if you need to switch compiler options or even compilers in different branches. In that case probably git-new-workdir is the best solution.

    0 讨论(0)
  • 2021-02-05 21:12

    If the compiled executables are files that have been checked in
    then git stash solves the problem.

    [compile]
    git stash save "first branch"
    git checkout other_branch
    [Fiddle with your code]
    [compile]
    git stash save "second branch"
    git checkout first_branch
    git stash apply [whatever index your "first branch" stash has]
    # alternatively git stash pop [whatever index...]
    

    If the compiled executables are files that have not and will not be checked in
    then simply add them to .gitignore

    0 讨论(0)
  • 2021-02-05 21:15

    You could set your IDE compiler to generate all private temporary files (.class and so on) in <output>\branchName\....

    By configuration your compilation setting branch by branch, you can register the name of the branch in the output directory path.

    That way, even if though private files remain when you git checkout, your project on the new branch is ready to go.

    0 讨论(0)
  • 2021-02-05 21:22

    Those files aren't tracked by Git or Subversion, so they're left alone on the assumption that they are of some use to you.

    I just do my checkouts in different directories. Saves me the trouble of doing cleanup.

    0 讨论(0)
  • 2021-02-05 21:23

    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.

    0 讨论(0)
  • 2021-02-05 21:25

    This is not git or svn specific - you should have your compiler and other tools direct the output of intermediate files like .o files to directories that are not under version control.

    0 讨论(0)
提交回复
热议问题