尝试同步分叉的GitHub存储库后,本地文件被还原

时间:2017-02-14 15:48:34

标签: git github version-control

我将GitHub上的biopython/biopython存储库分叉到BioGeek/biopython

我在我的本地存储库committed中做了一些更改,创建了一个pull request,它们是merged到上游biopython存储库中。到目前为止,非常好。

我在我的存储库中创建了一些further commits,同时在主biopython存储库中创建了一些other commits

现在我想更新我的本地存储库以从主存储库中获取更改,所以我这样做:

]

接下来我想更新分叉存储库中的master分支,所以我这样做:

someSuperWizardRegexReplaceStuffThatGetsRidOfMongoDBCrap

嗯,$ git pull upstream master remote: Counting objects: 12, done. remote: Compressing objects: 100% (5/5), done. remote: Total 12 (delta 9), reused 10 (delta 7), pack-reused 0 Unpacking objects: 100% (12/12), done. From https://github.com/biopython/biopython * branch master -> FETCH_HEAD 06b6cd64d..6e41879ca master -> upstream/master First, rewinding head to replay your work on top of it... Applying: add header back to 1LCD.pdb file Applying: actually check that the warning was raised instead of surpressing it $ git status On branch master Your branch and 'origin/master' have diverged, and have 100 and 3 different commits each, respectively. (use "git pull" to merge the remote branch into yours) Untracked files: (use "git add <file>..." to include in what will be committed) ../Doc/examples/tree1.nwk nothing added to commit but untracked files present (use "git add" to track) 。所以我从GitHub帮助中提取页面Syncing a fork并按照其中的说明进行操作:

$ git push origin master
To https://github.com/BioGeek/biopython.git
 ! [rejected]            master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/BioGeek/biopython.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

嗯,我必须使用rejected,所以我这样做

$ git fetch upstream
$ git checkout master
Already on 'master'
Your branch and 'origin/master' have diverged,
and have 100 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

但现在我在本地对文件1LCD.pdbtest_SeqIO_PdbIO.py所做的更改已经消失了!我已经提交了它们,所以如何将它们带回来以及我哪里出错了以便将来当我想要同步我的叉子时不会再次弄乱这个混乱。

1 个答案:

答案 0 :(得分:1)

你第一次没有使用最新的biopython大师。在提交Deprecate Bio.DocSQL之后,仍然有多个提交你没有在你的fork repo中提取,所以即使PR在biopython master中合并,但你的fork repo也不同。

enter image description here

因此,您可以保存未在另一个分支中推送的工作,然后删除本地主分支并将主biopython主服务器视为本地主分支,然后合并主服务器中的工作并删除临时分支,详细步骤如下:

git checkout -b temp
git branch -D master
git checkout upstream/master
git checkout -b master
git merge temp
git branch -D temp