从两台机器开发Git存储库设置? [英] Git repository setup for development from two machines?

查看:113
本文介绍了从两台机器开发Git存储库设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用git,并且对SVN的工作流差异印象深刻,但我遇到了一个结构/设置问题,文档似乎没有直观地解释如何设置,不知道是否有可能。

我的设置是我有几台电脑(台式机和笔记本电脑)开发,因此,为了更容易保持同步并为git存储库提供备份,我在我的家用Linux服务器上建立一个公共裸机存储库,我可以从台式机和笔记本电脑上进行登录。它不是真正公开的,因为它需要通过SSH访问盒子。



当我在桌面上进行更改时,我的问题就来了,我可以轻松地将更改推送到服务器存储库(我为该存储库上的 origin remote设置了 mirror 标志),并使用 gitx 我可以看到本地和远程状态看起来完全相同,并且我的每个单独提交都已经记录到服务器。



问题是,当我切换到笔记本电脑时,我很少使用笔记本电脑,git存储库可能会有几个提交服务器版本的提交并需要更新。我开始使用 git pull 来获取本地更改,但不是将服务器上的所有单个提交复制到本地存储库,而是向该存储库添加一个新的合并提交本地存储库和 gitx 显示远程存储库分支在该点的合并。

是否有命令/工作流让我将本地存储库更新为远程存储库的确切状态(例如,如果我执行 git push --mirror 没有数据会丢失)?我每次都必须删除我的本地存储库,并且每次都要删除 git clone 它吗?



目前没有其他人将需要访问这个存储库,但将来它可能会成为人们从中获取的公共存储库,所以不会破坏这种可能性的答案将不胜感激。



编辑:我的提交确实包含了脱离主分支的分支分支;这可能是触发 git pull 命令显示为合并的原因吗?是 - rebase 标记我需要的吗?

解决方案说明:事实证明,我已经完成了以下操作来设置我的存储库:


  • 使用便携式电脑初始化git存储库
  • 将笔记本电脑资源库推送到服务器(提交 A
  • B
  • 桌面克隆服务器存储库(提交 A 和提交(提交 C D E ,包括重新绑定分支)
  • 桌面推送到服务器(服务器快进至 E

  • 当笔记本电脑从服务器拉出时,会导致合并(因为 B 无法快进 )。

  • 笔记本电脑合并,并将更改推送到服务器。 现在,桌面也必须合并。 / li>


由于这是一个无意的额外提交newb错误,这让我认为它总是一个合并。根据Xentac的建议,我回到了笔记本电脑,发现我已经合并了一个并没有推送到服务器的罪魁祸首,一旦我全部同时完成了三个, git pull - > (只强制快进合并)工作得很好,并在合并之前提醒我是否有不同步的情况。

解决方案

因为您的笔记本电脑主分支中有不在服务器的主分支中的提交,所以每当服务器发生更改时,便携式计算机都无法更新主分支指针。这就是为什么你要创建合并提交。



如果你想继续进行没有存储在服务器上但只存储在你的笔记本电脑上的更改,你需要到 git fetch ,然后是 git rebase origin / master 。抓取将从服务器上下载提交,但不会更改您的本地分支,并且重新分配将在服务器的主分支(原始/主)上重新创建笔记本电脑的主分支更改。



尽管这些承诺悬而未决可能会更好。难道它们不能整合到整个代码库中,只有一个共同的历史吗?


I've just started using git, and am impressed with the workflow differences from SVN, but I've run into one structural/setup question that the documentation doesn't seem to intuitively explain how to set up, and I'm wondering if it's even possible.

My setup is that I have several computers I do development from (desktop and laptop), so, to more easily keep in sync and provide backup for the git repository, I set up a "public" bare repository on my home Linux server that I can ssh into from both desktop and laptop. It's not really public, since it requires SSH access to the box to get to.

My problem comes when I do changes on my desktop, I can easily push changes to the server repository (I have the mirror flag set for the origin remote on that repository), and using gitx I can see that the local and remote states look identical, and each of my individual commits has been logged to the server.

The question is when I switch to my laptop, which I use rather infrequently, the git repository there is likely several commits behind the server version and needs to be updated. I started using git pull to get those changes local, but rather than duplicate all the individual commits on the server to the local repository, it adds one new 'merge' commit to the local repository, and gitx shows merging in the remote repository branch at that point.

Is there a command/workflow that would let me update the local repository to the exact state of the remote repository (such that if I do a git push --mirror no data would be lost)? Would I have to delete my local repository each time and git clone it again each time?

Currently no one else would need access to this repository, though in the future it might become a public repository for people to pull from, so answers that don't destroy that possibility would be appreciated.

Edit: My commits do include rebasing branches off of the master branch; could that be what's triggering the git pull command to show as a merge? Is the --rebase flag what I need then?

Solution Explanation: It turns out I had done the following to set up my repositories:

  • Use laptop to initialize a git repository
  • Push laptop repository to server (commit A)
  • Made a change and committed it on the laptop (laptop at commit B)
  • Desktop clones server repository (commit A)
  • Make changes on desktop and commit (commits C, D, E, including rebasing branches)
  • Desktop pushes to server (server fast-forwards to E)
  • When laptop pulls from server, results in a merge (since B cannot fast forward to E).
  • Laptop merges, and pushes changes to the server
  • Desktop now has to merge as well.

Because of that one extra commit that was an unintentional newb mistake, it led me to think that it would always be a merge. On Xentac's suggestion, I went back and found on the laptop that I had made a merge that wasn't pushed to the server, which was the culprit, and once I got all three really in sync, git pull --ff (forcing only fast-forward merges) works just fine, and warns me if something is out of sync before doing the merge.

解决方案

Because you have commits in your laptop's master branch that aren't in your server's master branch, every time the server changes, the laptop can't just update the master branch pointer. That's why you're creating merge commits.

If you want to continue having changes that aren't stored on your server but just stored on your laptop, you'll want to git fetch and then git rebase origin/master. The fetch will download the commits from the server but not change your local branches and the rebase will recreate your laptop's master branch changes on top of the server's master branch (origin/master).

It'd probably be better to not have those commits dangling around though. Can't they be integrated into the whole codebase to just have one common history?

这篇关于从两台机器开发Git存储库设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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