繁体   English   中英

如何在git中更新我的分支?

[英]How do I update my branch in git?

(1)我在Github中分叉一个人的存储库,我们将该人的存储库称为remoteRepo,将我的github的存储库称为myRepo。 (2)我将其克隆到本地PC。 我用这个命令

$git clone [remoteRepo] -b [branch_name] /my/local/folder

现在,remoteRepo已更改。 我将更新本地文件,以便与他保持相同的源代码。

我确实是这样

$ git remote add upstream [remoteRepo]
$ git fetch upstream
$ git fetch upstream 
$ git merge upstream/[branch_name]

但这是行不通的。 什么都没更新,这是什么原因? 我遵循github帮助中的文档

$ git remote add upstream [remoteRepo]
$ git fetch upstream
$ git fetch upstream 
$ git merge upstream/[myBranch]

您尚未进行任何本地更改。 您已经掌握了远程仓库的最新信息,因此无需执行其他任何操作。

我不太明白你的问题。 如果要更改远程存储库的位置,可以进入.git文件夹并打开配置文件并更改您的远程服务器。

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@remote.com:folder/git_location.git

也有从命令行更改遥控器的命令。 github帮助-git remotes

您怎么知道它不起作用? 尝试使用“ git log”确认自动合并提交消息,并尝试使用“ git diff HEAD ^”查看合并的内容。 您也可以将原始合并略微简化为“ git pull up myBranch”。

[编辑]

这个对我有用。 这是下面的完整日志。 要诊断您的问题-当您执行“ git fetch”操作时,您应该会看到一些可以确认提取的内容。 在“远程添加”之后,“ git branch -a”是否列出了远程分支? 您还可以运行“ git remote show上游”以确认您的存储库已“连接”到另一个。 您正在从克隆的存储库中提取数据; 其他人正在摆脱它; 他们把工作推回去了吗? 否则,您将看不到它们的更改。

一个日志:

$ git clone dev1 -b br1 dev2
Cloning into 'dev2'...
done.
$ cd dev2
$ git remote add upstream ../dev1
$ git branch -a
* br1
  remotes/origin/HEAD -> origin/master
  remotes/origin/br1
  remotes/origin/master

# NOW change content in the 'dev1' (the remote repository)
$ cd ../dev1
$ git checkout br1
Switched to branch 'br1'
$ ls
bar.c   foo.c

$ FL='baz.c'; echo "stuff" > $FL; git add $FL; git commit -m "$FL"
[br1 ef45921] baz.c
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 baz.c
$ ls
bar.c   baz.c   foo.c

 # Now return to 'dev2' and 'pull'

$ cd ../dev2
$ ls
bar.c   foo.c

$ git pull upstream
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From ../dev1
 * [new branch]      br1        -> upstream/br1
 * [new branch]      master     -> upstream/master
You asked to pull from the remote 'upstream', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
$ git pull upstream br1
From ../dev1
 * branch            br1        -> FETCH_HEAD
Updating 207c1a2..ef45921
Fast-forward
 baz.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 baz.c

 # Confirm 'baz.c' exists on 'dev2'
$ ls
bar.c   baz.c   foo.c

git branch查看分支列表

使用git checkout <mainbranch>签出要合并更改的分支

git merge <theotherbranch>合并分支git merge <theotherbranch>

并推动变化

暂无
暂无

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

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