[英]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.