(1)我在Github分叉一个人的回购,让我们把这个人的回购称为remoteRepo,我的github的回购作为myRepo。 (2)我将它克隆到我的本地电脑。 我用这个命令,
$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 help
中的文件进行操作答案 0 :(得分:1)
$ git remote add upstream [remoteRepo]
$ git fetch upstream
$ git fetch upstream
$ git merge upstream/[myBranch]
您尚未进行任何本地更改。你已经掌握了远程仓库的最新信息,所以别无他法。
答案 1 :(得分:0)
我不太明白你的问题。如果要更改远程存储库的位置,可以进入.git文件夹并打开配置文件并更改远程存储库。
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@remote.com:folder/git_location.git
还有命令可以从命令行更改远程。 github help - git remotes
答案 2 :(得分:0)
你怎么知道它不起作用?尝试'git log'确认自动合并提交消息和'git diff HEAD ^'以查看合并的作用。你也可以将原始合并略微简化为'git pull upstream myBranch'。
[编辑]
它对我有用。这是一个完整的日志如下。要诊断你的问题 - 当你做'git fetch'时,你会看到确认获取的东西。在“远程添加”之后,'git branch -a'列出了远程分支吗?您还可以运行'git remote show upstream'来确认您的存储库与另一个存储库“已连接”。您正在从您克隆的存储库中提取;其他人正在逃避它;他们把工作推回去吗?否则你不会看到他们的变化。
日志:
$ 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
答案 3 :(得分:0)
查看git branch
签出要将更改合并到git checkout <mainbranch>
将分支与git merge <theotherbranch>
并推送更改