简体   繁体   English

github fork从原始仓库中获取所有更改

[英]github fork fetch all the changes from the original repo

Yesterday I did my first fork on github. 昨天我在github上做了我的第一个fork。

I modified something and then made a pull request to the original repo. 我修改了一些内容,然后向原始存储库发出了请求请求。

Then I've discovered that i did something wrong, now I want to sync my fork to the original repo so that all the changes i did (creating new files, modified some..) will be deleted. 然后我发现我做错了,现在我想将fork同步到原始仓库,以便删除我所做的所有更改(创建新文件,修改一些..)。

I tried with 我尝试过

git fetch upstream git merge upstream/master git fetch上游git merge上游/主

and the changes made on the original repo in the meantime get synced to my fork but the changes i did remained in my fork ! 并且在此期间对原始存储库所做的更改已同步到我的fork中, 但是我所做的更改仍保留在我的fork中

I want my repo to be the same as the original one. 我希望我的仓库与原始仓库相同。

You can fix your fork by adding a remote to the original repo, fetch from there, reset your branches to match the ones pulled, then force push the branches to your fork. 您可以通过在原始仓库中添加一个遥控器来修复货叉,从那里获取信息,重设分支以匹配拉出的分支,然后将分支强行推入货叉。

Assuming your forked repo is represented by origin, here is an example with master as the only branch you have: 假设您的分叉存储库由原点表示,这是一个示例,其中master是您唯一的分支:

git remote add upstream http://github.com/original.git
git fetch upstream
git reset --hard upstream/master
git push -f origin master

now master will be in the same place in both repos. 现在,master将在两个存储库中位于同一位置。 When you do a merge, you either move the reference forward (called a fast-forward merge) because nothing existed on your side, or you make a new commit as there are changes to both. 进行合并时,您将向前移动参考(称为快速向前合并),因为这边不存在任何内容,或者您​​对两者都进行了更改,因此进行了新的提交。 Reset is the answer here if you want to throw away your commits - not merge. 如果您要放弃提交而不是合并,这里就是“重置”的答案。

If you have other branches that you want to reset back to where they are on the initial repo you can do it without checking them out with: 如果您有其他分支要重置回初始存储库中的位置,则可以执行以下操作,而无需使用以下命令将它们检出:

git push -f . upstream/feature1:feature1
git push -f origin feature1

the . . says push within the same repo. 说在同一仓库内推。 It's a clever way to move a branch pointer without having to checkout the branch. 这是一种移动分支指针而不必检出分支的聪明方法。 The colon syntax in push means <source>:<destination> . push中的冒号语法表示<source>:<destination> If :<destination> is omitted, it implies the same name which is why you don't often see the syntax with push examples. 如果省略:<destination> ,则表示相同的名称,这就是为什么您不经常在push示例中看到语法的原因。 A more common example is when you push a local branch to a remote one that has a different name: git push origin myexperiment:dev would update the dev branch on the remote to what myexperiment points to. 一个更常见的示例是,当您将本地分支推送到具有不同名称的远程分支时: git push origin myexperiment:dev会将远程计算机上的dev分支更新为myexperiment指向的分支。

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

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