1
如果我做git fetch origin master做git diff ...如果我做git fetch(沒有指定分支),origin不會有相同的結果,然後做git diff ...原點(見下文)。這是爲什麼? (只是要注意:Git版本1.7.3.1.msysgit.0)爲什麼git fetch指定分支不匹配沒有指定分支匹配(爲了區別)
git init parent && cd parent
echo 'version1' > contents.txt
git add contents.txt
git commit -m "version1"
cd ..
git clone parent child
cd child
echo 'child' >> contents.txt
git commit -a -m "Child"
cd ../parent
echo 'parent' >> contents.txt
git commit -a -m "Parent"
cd ../child
git fetch origin master
git diff ...origin
echo Expected diff here and it wasn't there!
git fetch
git diff ...origin
echo Ok, diff appeared properly now!
非常感謝......該操作似乎仍不自然,現在至少我知道現在發生了什麼:)有什麼從FETCH_HEAD更新我的本地原點/主的方法? –
在您的示例中,您的本地「主」分支跟蹤原點的主分支。所以你可以發出'git merge FETCH_HEAD'來合併你用'git fetch origin master'獲取的變化。另外,你可以用'git fetch origin master:refs/remotes/origin/master'直接讀取'origin/master'指針,然後'git merge origin/master'。坦率地說,在日常運營中,這並不重要。要麼工作。我習慣和懶惰使用'FETCH_HEAD'版本。你也可以看看'git pull',它同時執行'fetch'和'merge'。 – Christopher