2012-03-12 147 views
9

pwd是「當前工作目錄」。這是情況。git pull在指定位置的本地倉庫(而不是pwd)

pwd:   /path/to/pwd/ 
git repository: /repo/path/.git/ 

我想從原點做一個git pull,但不改變我的當前目錄。

爲了澄清只是更多的情況下,我不太清楚,這是我想要的結果,但我想用一個命令來做到這一點,而不必更改目錄:

$ cd /repo/path 
$ git pull origin master 
$ cd - 
+0

這是什麼情況? (我只是好奇。) – KajMagnus 2017-04-08 05:46:31

+0

@KajMagnus這是5年前,我真的不記得了。可能是想用單線更新repo,所以我可以根據需要使用'^ r'重複運行它,並且不會搞亂目錄堆棧,因爲我經常使用'pushd','popd'和'cd -'。 – Matthew 2017-04-13 22:43:48

+1

可能重複[git --git-dir不按預期工作](http://stackoverflow.com/questions/1386291/git-git-dir-not-working-as-expected) – pjgranahan 2017-04-27 07:11:42

回答

18
git --work-tree=/repo/path --git-dir=/repo/path/.git pull origin master 
+0

這很難適用。你能舉一個公共回購的例子嗎? – Cognitiaclaeves 2016-09-06 19:55:49

+0

@Cognitiaclaeves,不確定你的意思是「難以申請」?剛剛嘗試過,它「只是工作」。它應該與你有權訪問的任何回購公開或不公開。 – 2017-03-05 20:43:29

4

慶典-c「cd/repo/path; git pull origin master」

+0

是否真的沒有git選項爲了這? Git的功能正在爆炸式增長,似乎很難相信你必須將你的工作目錄放在版本庫位置或其子目錄中。 – Matthew 2012-03-12 19:06:30

+0

哦,我不知道。如果有一種方式,我全部耳朵! :)我只是想給你一個班輪。 – sethcall 2012-03-12 19:08:47

+0

不需要'bash -c',你可以用'(list)'在子shell中執行列表:'(cd/repo/path; git pull origin master)' – 2017-04-27 09:37:03