簡體   English   中英

git pull 后 master 之前的本地分支

[英]Local branch ahead of master after git pull

我正在一個沒有我的 git 憑據的遠程服務器上工作,我想從 master 中提取。 我沒有本地提交,我只想更新這台機器上的本地存儲庫以匹配遠程存儲庫(來源)。 使用這個答案,我設法更新了存儲庫:

my_repo$ git pull https://my_user@github.com/my_repo
Password for 'https://my_user@github.com': 
<some updates....>

實際上,在此操作之后,本地存儲庫已更新為包含與遠程存儲庫完全相同的所有提交。

但是,由於某種原因,我無法理解,本地存儲庫變得領先於 master,我找不到修復它的方法。 這怎么可能???

my_repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
    

my_repo$ git push https://my_user@github.com/my_repo
Password for 'https://my_user@github.com': 
Everything up-to-date

my_repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

my_repo$ git pull https://my_user@github.com/my_repo
Password for 'https://my_user@github.com': 
From https://github.com/my_repo
 * branch            HEAD       -> FETCH_HEAD
Already up to date.

另外,當我使用git log時,我看到了這個奇怪的結果,這對應於我的分支領先於 master,但不對應於“現實”:

my_repo$ git log --pretty=oneline
09ee1f2 (HEAD -> master) Latest commit on master
b6433fb Another commit from master
31da031 Another commit from master
85b95ae (origin/master, origin/HEAD) Another commit from master which was the head before pulled

有人對如何解決這個問題有任何建議嗎? 以及關於這是如何發生的以及我將來如何避免這種情況的任何想法?

謝謝!

您的來源/主人已過時。

從 URL 拉出是一次性的。 它不會更新原點/主控。

origin 是與特定 URL 關聯的遠程存儲庫的名稱。 origin/master 是您最后一次在 origin 上看到 master 分支。 origin/master 只會使用git fetchgit pull from origin 進行更新。 這還沒有發生。

相反,您已經通過從一些不同的 URL 中提取來更新 master。 它可能與原始存儲庫相同,但 Git 不知道這一點。 您可以通過使用git remote set-url origin https://my_user@github.com/my_repo更改原點 url 來解決此問題。 然后git fetch origin

請參閱 Pro Git 中的遠程分支

感謝@Schwern 的回答,我能夠理解這個問題。

我是如何解決的:

  1. 使用這個精彩的網站恢復“本地”提交:

     git reset --hard @{u}
  2. 通過從gitconfig刪除憑據,確保此計算機上的此存儲庫中沒有現有憑據:

     sudo subl ~/.gitconfig // or any other text editing instead of subl
  3. “定期”拉動,即不指定我的憑據:

     my_repo$ git pull Username for 'https//github.com': my_user Password for 'https://my_user@github.com': <updates...>

現在一切都很好...

再次感謝@Schwern 解釋問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM