我有几个依赖于同一个库的项目,为此我想维护一个单独的 git 存储库,以便在每个项目中使用 git-subtree 进行管理。因此,例如,在每个项目中我可以做:
project1$ git subtree add --prefix=lib1 /path/to/lib1.git master
project2$ git subtree add --prefix=lib1 /path/to/lib1.git master
现在在处理 project1 的过程中,我对 lib1 做了一些更改,比如 lib1/file1.c,并将其推送回中央仓库:
project1$ git add lib1/file1.c
project1$ git commit -m "updates to lib1"
project1$ git subtree push --prefix=lib1 /path/to/lib1.git master
到目前为止,还不错。但现在我想更新 project2 的 lib1 副本。所以我尝试:
project2$ git subtree pull --prefix=lib1 /path/to/lib1.git master
Auto-merging lib1/file1.c
CONFLICT (content): Merge conflict in lib1/file1.c
Automatic merge failed; fix conflicts and then commit the result.
这是怎么回事?我很确定project2下的lib1文件没有任何变化,所以这里为什么会发生冲突?
冲突是半空的,如 this question 中报告的那样.一切都在单个系统 (OS X) 中被 pull/推,所以我知道那里建议的行结尾没有问题。
这当然是 git-subtree 的常见用例,并且有一个我看不到的简单答案。请帮忙!
编辑:我发现了一个不令人满意的解决方法:将更改推送到子树后,我需要立即重新运行子树 pull :
project1$ git subtree push --prefix=lib1 /path/to/lib1.git master
project1$ git subtree pull --prefix=lib1 /path/to/lib1.git master
即使没有任何变化,它也会找到一些东西,并进行 merge 提交。然后,在其他地方进行一些更改后,我第二次从中央 repo 中 pull 出时不会发生冲突。但是如果我忘记在 push 之后立即运行 pull,那么下一次 pull 就会发生这个冲突。
所以现在我的问题是,为什么这样做有效? git-subtree 跟踪推送的方式是否存在错误,或者我是否遗漏了什么?
最佳答案
实际上,我通过反复试验找到了执行此操作的正确方法。
执行此命令后:
project1$ git subtree push --prefix=lib1 /path/to/lib1.git master
执行一个获取命令:
project2$ git fetch /path/to/lib1.git master
然后做你的 pull :
project2$ git subtree pull --prefix=lib1 /path/to/lib1.git master
关于从中央 repo 中 pull 出时 git-subtree 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17242063/
文章目录git常用命令(简介,详细参数往下看)Git提交代码步骤gitpullgitstatusgitaddgitcommitgitpushgit代码冲突合并问题方法一:放弃本地代码方法二:合并代码常用命令以及详细参数gitadd将文件添加到仓库:gitdiff比较文件异同gitlog查看历史记录gitreset代码回滚版本库相关操作远程仓库相关操作分支相关操作创建分支查看分支:gitbranch合并分支:gitmerge删除分支:gitbranch-ddev查看分支合并图:gitlog–graph–pretty=oneline–abbrev-commit撤消某次提交git用户名密码相关配置g
关于如何使用git设置类似Dropbox的服务,您有什么建议吗?您认为git是解决此问题的合适工具吗?我在考虑使用git+rush解决方案,你觉得怎么样? 最佳答案 检查这个开源项目:https://github.com/hbons/SparkleShare来自项目的自述文件:Howdoesitwork?SparkleSharecreatesaspecialfolderonyourcomputer.Youcanaddremotelyhostedfolders(or"projects")tothisfolder.Theseprojec
我编写了一个非常简单的“部署”脚本,作为我的裸git存储库中的post-updateHook运行。变量如下livedomain=~/mydomain.comstagingdomain=~/stage.mydomain.comgitrepolocation=~/git.mydomain.com/thisrepo.git(bare)core=~/git.mydomain.com/thisrepo.gitcore==addedremoteintoeachlive&stagegitslive和stage都初始化了gitrepos(非裸),我已经将我的裸仓库作为远程添加到它们中的每一个(名为co
我正在安装gitlabhq,并且在Gemfile中有对某些资源的“git://...”的引用。但是,我在公司防火墙后面,所以我必须使用http://。我可以手动编辑Gemfile,但我想知道是否有另一种方法告诉bundler使用http://作为git存储库? 最佳答案 您可以通过运行gitconfig--globalurl."https://".insteadOfgit://或通过将以下内容添加到~/.gitconfig:[url"https://"]insteadOf=git://
Activeadmingem已添加到我的rails项目中,但每次我尝试安装railsgactive_admin:install时,我都会收到类似的错误git://github.com/activeadmin/activeadmin.git(atmaster)isnotyetcheckedout.Runbundleinstallfirst.我肯定在运行“railsgactive_admin:install”之前运行了bundle。运行“bundleshow”后,我看到我已将“*activeadmin(1.0.0.pre3f916d6)”添加到我的项目中,但不断收到此错误消息。我的gem文
当你在类中包含方法名冲突的模块时,它会使用类定义的方法。有没有办法选择我想运行的?moduleBdefself.hello"helloB"endendclassAincludeBdefself.hello"helloA"endendA.hello#=>thisprints"helloA",whatifIwant"helloB"? 最佳答案 Ben,当你在Ruby中调用一个方法(比如hello)时,会发生以下情况:如果接收者的特征类有一个名为hello的方法,它将被调用。如果不是:如果接收者的类有一个名为hello的实例方法,它将被调
我已经安装了最新版本的compass、sass和susy。但我仍然收到此错误:Unabletoactivatesusy-2.1.1,becausesass-3.2.17conflictswithsass(~>3.3.0)有人知道这个Ruby是如何工作的吗?这是我安装的gem的列表:***LOCALGEMS***CFPropertyList(2.2.0)chunky_png(1.3.0)compass(0.12.4)compass-core(1.0.0.alpha.19)compass-import-once(1.0.4)compass-rails(1.1.3)fssm(0.2.10)l
我前段时间为我的Rails应用程序创建了一个heroku存储库,但由于我从未使用过它而删除了它。现在我已经到了需要使用heroku的地步,但我遇到了以下错误:!Nosuchappasfurious-mist-2295.这是旧的repo名称,所以它显然没有推送到我创建的新堆栈。这是我正在考虑尝试的方法,但我担心会对我的git存储库造成不必要的更改。gitremotermorigingitremoteaddorigingitpush-uoriginmaster 最佳答案 原来可以用下面的命令来完成gitremotermherokugit
我在bitbucket上创建了一个私有(private)git存储库并提交了代码。现在我想导出所有(提交、代码、历史记录)并将其导入github上的gitrepo。有没有办法做到这一点?谢谢 最佳答案 在本地检查所有内容到您的计算机和gitpull。创建一个github存储库将此存储库添加为您的第二个远程(“使用gitremote添加githubURL”)推送到第二个Remote 关于ruby-git:从bitbucket导出并导入github(带提交),我们在StackOverflow
亲测可用。Anerroroccurredwhileresolvingpackages:Projecthasinvaliddependencies: com.unity.xxx:No'git'executablewasfound.PleaseinstallGitonyour systemthenrestartUnityandUnityHub在我们使用PackageManager时,Unity允许我们使用Git上的package(点击加号,选择addpackagefromgitURL,或者是直接在Asset/Packages/manifest.json中添加包名)。但是这种操作需要我们事先装好g