[英]Update modified git repo?
I have a repository on git, which I am cloning from into a server that compiles and runs it. 我在git上有一个存储库,我正从该存储库克隆到编译并运行它的服务器中。
Since that server is local on my network, I can further clone the project that is accessible via samba or even open it on my preferable editor and work on it from there, doing the changes I need or anything else. 由于该服务器是我网络上的本地服务器,因此我可以进一步克隆可通过samba访问的项目,甚至可以在我喜欢的编辑器中将其打开,然后从那里进行处理,进行所需的更改或其他操作。
Here is where things get complicated, I would like to be able to keep the clone I have on my server, synchronized(up to date) with the git repository(which I can't push things to), while retaining the changes I do locally to my server repository. 这是使事情变得复杂的地方,我希望能够将服务器上的克隆与git存储库(我无法将其推送到)保持同步(最新),同时保留所做的更改本地到我的服务器存储库。
What is the most common practice if there is one for this specific case or what should be the advised route to follow for this? 如果针对这种特定情况有一种最常见的做法,或者应该遵循的建议路线是什么?
If I had to describe the current process I do, it would look something like this: 如果必须描述当前的过程,它将看起来像这样:
I assume, I would in either case need steps 1 and 2 because if I commit git would complain about changed files not allowing to simple git pull
it. 我认为,无论哪种情况,我都需要步骤1和2,因为如果我提交git,将会抱怨更改的文件不允许简单的git pull
它。
An alternative to the above, I think would be something like: 除了上述以外,我认为应该是这样的:
So repeating my question again: 因此,再次重复我的问题:
I am not an expert in git, I do know how to use part of it, but the above scenario is something new for me. 我不是git的专家,我确实知道如何使用它的一部分,但是上述情况对我来说是新的东西。
Why don't you use a branch ? 为什么不使用分支 ?
The moment you cloned the repository, you got a local one. 克隆存储库的那一刻,您获得了本地存储库。 You can create branches and use them to version your code locally, without ever pushing to the remote. 您可以创建分支并使用它们在本地对代码进行版本控制,而无需推送到远程。
Create your own branch based on master 基于master创建自己的分支
git checkout master
git checkout -b mybranch
Keep commiting your changes to mybranch
. 继续对mybranch
更改。 Whenever changes appear in the remote repository, update master
and merge it into mybranch
. 每当远程存储库中出现更改时,请更新master
并将其合并到mybranch
。
You could also share your work with others if you set up your own remote . 如果您设置了自己的遥控器,也可以与他人共享您的工作。 Git allows you to work with multiple remote repositories. Git允许您使用多个远程存储库。 If you don't have access to the one you used to clone the project, nothing stops you from creating your own one where you do. 如果您无权访问用于克隆项目的项目,那么任何事情都不会阻止您创建自己的项目。
First you should follow the instructions from the GitHub help to create a fork . 首先,您应该按照GitHub帮助中的说明创建分叉 。 After you do this, you will have a local repo and a personal clone (or fork) on the GitHub servers. 完成此操作后,您将在GitHub服务器上拥有一个本地存储库和一个个人克隆(或fork)。 The local repo has two "remotes". 本地仓库有两个“远程”。 origin
points to your personal GitHub repo. origin
指向您的个人GitHub存储库。 upstream
points to the original main repo. upstream
指向原始主仓库。
Now when you want to make your own changes, you should create a branch: 现在,当您要进行自己的更改时,应该创建一个分支:
$ git checkout -b mybranch master
This command will create the branch and check it out. 该命令将创建分支并将其检出。 Now you can use git add
and git commit
to commit your changes to your local repo. 现在,您可以使用git add
和git commit
来将更改git commit
到本地仓库。
If you decide you want to submit your changes to the original repo, then you first need to push your branch to your personal GitHub repo: 如果您决定要将更改提交到原始存储库,则首先需要将分支推送到您的个人GitHub存储库:
$ git push origin mybranch
Then log in to your GitHub account and create a Pull Request. 然后登录到您的GitHub帐户并创建一个请求请求。 Your changes will be reviewed by the maintainers of the original repo. 您的更改将由原始存储库的维护者审查。 Most likely they will give suggestions of what you need to do to improve your changes before being accepted. 在接受之前,他们很可能会提出您需要做些什么来改进您的更改的建议。
When the original repo is updated, you can pull those changes to your local repo with 原始存储库更新后,您可以使用以下命令将这些更改拉到本地存储库中
$ git checkout master
$ git pull upstream master
You can also update your personal GitHub repo with 您还可以使用以下命令更新您的个人GitHub存储库
$ git push origin master
And you can merge the changes into your own work with 您可以将更改合并到自己的工作中
$ git checkout mybranch
$ git merge master
If there are any conflicting changes between the update to the original repo and your own work, then git will tell you. 如果在原始存储库的更新和您自己的工作之间存在任何冲突的更改,那么git会告诉您。 Then you have to manually resolve these conflicts. 然后,您必须手动解决这些冲突。 You can do this directly in any text editor or use one of the many visual tools which are available. 您可以直接在任何文本编辑器中执行此操作,也可以使用许多可用的可视化工具之一。 See How to resolve merge conflicts in Git? 请参阅如何解决Git中的合并冲突? for details. 有关详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.