git合并两个不同存储库的同一目录 [英] git Merging same directory of two different repositories

查看:338
本文介绍了git合并两个不同存储库的同一目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个托管在git-hub上的开源项目。

我也在这个项目中做了很多改变,并保存在另一个本地存储库中。



所以当我需要从git-hub中获取新的变更时,我正面临着两个问题(我的本地存储库和git-hub的变化)



例如:项目1 - > local1
也来自github:project 1 - > git-1
**这些更改位于同一个目录中。
目前我正在以下步骤合并这两个:


  1. 用git3替换本地存储库代码(现在树是project1-> git1)

  2. 将它与head(它是project1-> local1)进行比较

  3. 更新local1的更改(head现在是project1-> local1-> git1-local merge)

但是如果有任何来自git-hub的新更新(比如说tree是project1-> git1-> git-2)
和我的本地(project1-> local1-> local2)中的新更新。如果我现在要合并这两个,我必须再次重复(再次添加local1的更改)。我很好,如果不知何故,我只能添加local2的变化。



我希望我清楚我在说什么。

解决方案

手动执行操作确实很困难,您会使任务复杂且容易出错。
$ b

Git可以通过指定远程存储库的状态来帮助您,例如 origin / branch origin / master 等。



请参阅 git merge origin / branch 等命令, git chekout branch ,以及类似的东西。您不需要不同的工作副本,也不需要在目录之间手动移动东西。 Git在切换不同分支时为您处理它。


I am using one open source project which is hosted on git-hub.

I am also making lots of changes in this project at my end and keeping this in my another local repository.

So when i need to fetch new changes from git-hub I am facing issues in merging both (changes of my local repository and the git-hub)

For example : project 1 -> local1 also from github : project 1 -> git-1 **these changes are on same directory. Currently i am merging these two in below steps:

  1. Replace the local repository code with git3 (now tree is project1->git1)
  2. compare it with head (which is project1->local1)
  3. Update the local1 changes (head is now project1->local1->git1-local merge)

but in case of any new update from git-hub (say now tree is project1->git1->git-2) and new update in my local (project1->local1->local2) .if i now go for merging of these two ,i have to again repeat (again add the changes of local1) . i am fine if somehow i can only add the changes of local2.

I hope i am clear in what i am trying to say.

解决方案

Doing things manually is really difficult, you're making the task complex and error-prone.

Git can help you with this, by designating states of remote repositories with referencs, like origin/branch, origin/master, etc.

See commands such as git merge origin/branch, git chekout branch, and stuff like this. You don't need different working copies, nor manually moving stuff between directories. Git handles it for you when switching different branches.

这篇关于git合并两个不同存储库的同一目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆