git 和 C++ 工作流程,如何处理对象和归档文件?
我使用 git 与 SVN 存储库交互。 我有几个 git 分支用于我从事的不同项目。
现在,每当我使用“git checkout”从一个分支切换到另一个分支时,前一个分支中所有已编译的可执行文件和目标文件仍然存在。 我希望看到的是,从分支 A 切换到 B 会生成一棵树,其中包含我上次在分支 B 上工作时的所有对象文件和二进制文件。
有没有办法在不创建多个 git 存储库的情况下处理此问题?
更新:我知道可执行文件和二进制文件不应该出现在存储库中。 我有点失望,因为 git 中的所有分支内容对我来说都没用,因为事实证明我必须为我想要启动的每个分支克隆我的代理 git 存储库。 我已经为 SVN 做了一些事情,并希望用 git 来避免。 当然,我不必这样做,但这会导致我在分支之间切换后大部分时间都会进行新的制作(不好玩)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您想要的是完整的上下文,而不仅仅是分支......这通常超出了版本控制工具的范围。 最好的方法是使用多个存储库。
不过,不要担心这样做的低效率...让您的第二个存储库成为第一个存储库的克隆。 Git 会自动使用链接来避免磁盘上有多个副本。
这里有一个技巧可以满足您的需求
由于您有单独的 obj 目录,因此您可以修改 Makefiles,使用类似以下内容使基本位置动态化:
这会将您的分支名称转换为 OBJBASE,您可以使用可以用来构建您的实际 objdir 位置。 我将让您修改它以适应您的环境并使其对 Makefiles 的非 git 用户友好。
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:
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.
这不是 git 或 svn 特定的 - 您应该让编译器和其他工具将中间文件(如 .o 文件)的输出定向到不受版本控制的目录。
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.
要保留同一存储库的多次签出,您可以使用 git --work-tree。
例如,
To keep multiple checkouts of the same repo, you can use git --work-tree.
For example,
您可以将 IDE 编译器设置为在
中生成所有私有临时文件(.class 等)。
通过逐个分支配置编译设置,您可以在输出目录路径中注册分支的名称。
这样,即使您在 git checkout 时保留了私有文件,您在新分支上的项目也已准备就绪。
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.在
git
发行版的contrib/
目录中,有一个名为git-new-workdir
的脚本,它允许您签出不同位置的多个分支。目录而不克隆您的存储库。In the
contrib/
directory of thegit
distribution, there is a script calledgit-new-workdir
that allows you to checkout multiples branches in different directories without cloning your repository.这些文件不会被 Git 或 Subversion 跟踪,因此我们会假设它们对您有用,所以将它们保留下来。
我只是在不同的目录中进行结帐。 省去了我清理的麻烦。
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.
不需要进行 make clean,因为不同分支之间不同的文件会以实际日期检出!
这意味着,如果您的 Makefile 正确,则只会再次编译那些因检出而真正更改的目标文件、库和可执行文件。 这正是 makefile 存在的首要原因。
例外情况是您需要切换编译器选项甚至不同分支中的编译器。 在这种情况下, git-new-workdir 可能是最好的解决方案。
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.
如果编译后的可执行文件是已签入的文件
然后 git stash 解决了问题。
如果编译后的可执行文件尚未签入,也不会签入
然后只需将它们添加到 .gitignore
If the compiled executables are files that have been checked in
then git stash solves the problem.
If the compiled executables are files that have not and will not be checked in
then simply add them to .gitignore