git 和 C++ 工作流程,如何处理对象和归档文件?

发布于 2024-07-15 09:20:08 字数 427 浏览 5 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

樱花落人离去 2024-07-22 09:20:08

您想要的是完整的上下文,而不仅仅是分支......这通常超出了版本控制工具的范围。 最好的方法是使用多个存储库。

不过,不要担心这样做的低效率...让您的第二个存储库成为第一个存储库的克隆。 Git 会自动使用链接来避免磁盘上有多个副本。

这里有一个技巧可以满足您的需求

由于您有单独的 obj 目录,因此您可以修改 Makefiles,使用类似以下内容使基本位置动态化:

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"

这会将您的分支名称转换为 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:

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.

贪恋 2024-07-22 09:20:08

这不是 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.

走走停停 2024-07-22 09:20:08

要保留同一存储库的多次签出,您可以使用 git --work-tree。
例如,

mkdir $BRANCH.d
GIT_INDEX_FILE=$BRANCH.index git --work-tree $BRANCH.d checkout $BRANCH

To keep multiple checkouts of the same repo, you can use git --work-tree.
For example,

mkdir $BRANCH.d
GIT_INDEX_FILE=$BRANCH.index git --work-tree $BRANCH.d checkout $BRANCH
做个少女永远怀春 2024-07-22 09:20:08

您可以将 IDE 编译器设置为在 \branchName\... 中生成所有私有临时文件(.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.

零崎曲识 2024-07-22 09:20:08

git 发行版的 contrib/ 目录中,有一个名为 git-new-workdir 的脚本,它允许您签出不同位置的多个分支。目录而不克隆您的存储库。

In the contrib/ directory of the git distribution, there is a script called git-new-workdir that allows you to checkout multiples branches in different directories without cloning your repository.

我的奇迹 2024-07-22 09:20:08

这些文件不会被 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.

别理我 2024-07-22 09:20:08

不需要进行 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.

南渊 2024-07-22 09:20:08

如果编译后的可执行文件是已签入的文件
然后 git stash 解决了问题。

[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...]

如果编译后的可执行文件尚未签入,也不会签入
然后只需将它们添加到 .gitignore

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文