如何在提交后使fork与upstream / master对齐

时间:2015-12-15 22:49:36

标签: git github

我在fork上做了一个小编辑,然后我想在上游添加。我看到我的分叉已落后于8次提交,我想让它更新没有合并分支'主'消息

我添加了一个上游遥控器:

$ git remote add upstream https://github.com/docker/leeroy
origin  git@github.com:mjbrender/leeroy.git (fetch)
origin  git@github.com:mjbrender/leeroy.git (push)
upstream    https://github.com/docker/leeroy (fetch)
upstream    https://github.com/docker/leeroy (push)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes not staged for commit:
    modified:   github.go
no changes added to commit

认为正确的工作流程是fetch upstream/master分支,pull它然后我会同步。当我这样做时,我似乎已经合并了:

git fetch upstream master
remote: Counting objects: 19, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 19 (delta 9), reused 18 (delta 8), pack-reused 0
Unpacking objects: 100% (19/19), done.
From https://github.com/docker/leeroy
 * branch                      master     -> FETCH_HEAD
 * [new branch]                master     -> upstream/master
$ git pull upstream master
From https://github.com/docker/leeroy
 * branch                      master     -> FETCH_HEAD
Removing Dockerfile.build
Merge made by the 'recursive' strategy.
 Dockerfile                  | 36 ++++++++++++++++++++++++++++--------
 Dockerfile.build            | 21 ---------------------
 MAINTAINERS                 | 33 +++++++++++++++++++++++++++++++++
 README.md                   | 10 ++++++----
 github/pull_request.go      | 14 --------------
 github/pull_request_test.go | 28 ----------------------------
 handlers.go                 | 17 +++--------------
 7 files changed, 70 insertions(+), 89 deletions(-)
 delete mode 100644 Dockerfile.build
 create mode 100644 MAINTAINERS
$ git status
On branch master
Your branch is ahead of 'origin/master' by 9 commits.
nothing to commit, working directory clean

我相信我需要将我的默认拉动行为编辑为rebase而不是merge。我在这里的问题是:如何返回到upstream/master之前提交1的状态,以便我可以打开拉取请求?

2 个答案:

答案 0 :(得分:3)

如果我理解正确,你实际上想要弹出你在本地提交的提交,更新以与upstream/master同步,然后将你的提交重新推送到顶部而不进行任何合并提交。你可以用一个简单的命令完成所有这些:

git pull --rebase . upstream/master

你也可以用另一种方式完成。首先更新你的遥控器,然后改变:

git remote update
git rebase upstream/master

答案 1 :(得分:-2)

我很重要的是要理解Git分支只是提交的指针。您想要做的是简单地将当前分支的指针恢复到工作目录的先前位置。 HEAD@{1}有一个Git快捷方式。

快捷方式查看reflog(这是特定ref在本地计算机上的位置的日志。),因此它与您在git log中看到的内容无关。

这实际上会移动:

git reset --hard HEAD@{1}