简体   繁体   English

Git-如何保持克隆的存储库更新

[英]Git - How to keep cloned repository updated

I cloned a repository using the tutorial on Github . 我使用Github上的教程克隆了一个存储库。 I regularly change things in the cloned repository. 我定期更改克隆存储库中的内容。 From time to time I want to merge the changes from the original repository. 我不时要合并原始存储库中的更改。

This works, but I have to merge things that I merged some time ago again. 这可行,但是我必须重新合并前一段时间合并的东西。 So you can see that the left and right side are identical, but the merged version contains an old version that was there when originally cloning the repository. 因此,您可以看到左侧和右侧相同,但是合并的版本包含最初克隆存储库时存在的旧版本。

How to keep the cloned repository up to date with the original repository without merging changes over and over again, every time something changes in the file. 每当文件中发生某些更改时,如何使克隆的存储库与原始存储库保持最新,而又不会一遍又一遍地合并更改。

I will add a small example: 我将添加一个小示例:

At one point the original repository changes method a() of Class C to b() and I merge that change. 最初,原始存储库将C类的方法a()更改为b(),然后我将这一更改合并。 If in the future something else in Class C changes, I see that my local version contains method b() and the remote version contains method b(), but the merged version contains method a(). 如果将来C类中的其他内容发生变化,我会看到本地版本包含方法b(),远程版本包含方法b(),但是合并版本包含方法a()。

  • After cloning a repository, create a new branch for working . 克隆存储库后,创建一个新分支以进行工作。
  • On that new branch, do your work and commit. 在该新分支上,执行您的工作并提交。
  • When original updates, checkout master and pull. 原始更新时,签出母版并拉出。
  • Merge your new branch with master. 将您的新分支与master合并。
  • Create another new branch for continue working with new version of original cloned. 创建另一个新分支,以继续使用原始克隆的新版本。

So you have to merge only one time when original update ! 因此,原始更新时只需要合并一次!

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

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