简体   繁体   English

如何同步两个具有唯一分支提交的“.git”本地存储库?

[英]How can I sync two `.git` local repositories with unique branch commits?

Both .git repositories are on the same machine but different folders, and belong esentially to the same project. .git存储库都在同一台机器上,但文件夹不同,本质上属于同一个项目。 To keep it simple, let's say both copies have two branches:为简单起见,假设两个副本都有两个分支:

  • The master (or Alpha) branch. master (或 Alpha)分支。 Last commits to this branch were made in folderA 's .git repository.对该分支的最后一次提交是在folderA.git存储库中进行的。
  • The stable (or Beta) branch. stable (或 Beta)分支。 Last commits to this branch were made in folderB 's ·git repository对该分支的最后一次提交是在folderB·git repository中进行的

So, I want to make both branches hold the last changes in both git folders again.所以,我想让两个分支再次保存两个git文件夹中的最后更改。 So, after cleaning both working directories, I guess I just could copy the whole directory project's files from folderB and make a single commit to the stable branch inside folderA .因此,在清理了两个工作目录之后,我想我可以从folderB复制整个目录项目的文件,并对folderAstable分支进行一次提交。 However, I'd like to conserve all the commits from folderB as well instead.但是,我也想保留来自folderB的所有提交。 (next time I should not forget to copy the master .git directory to the beta folder before making any hotfixes to the Beta version so I would not have this problem anymore; but what is done is done ^^') (下次我不应该忘记在对 Beta 版本进行任何修补程序之前将主目录.git复制到 beta 文件夹,这样我就不会再遇到这个问题了;但是已经完成了 ^^')

If it was "local to remote", making a "pull request" would be the way to go I guess.如果它是“本地到远程”,那么提出“拉取请求”将是 go 我猜的方式。 But in my case, both copies of the repository are on the same machine.但就我而言,存储库的两个副本都在同一台机器上。

Is there any git command to perform such a thing?有没有 git 命令来执行这样的事情?

You can add a local repository as a remote and use git pull and handle merge conflicts, etc. as usual您可以将本地存储库添加为远程,并像往常一样使用git pull和处理合并冲突等

For example例如

$ cd /path/to/folderB/
$ git remote add localA /path/to/folderA
$ git checkout master
$ git pull localA master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM