說我有一個工作樹和/或索引是「髒的」(即我有本地修改還沒有提交或隱藏),我試圖做一個「混帳拉」沒有第一次提交或積攢。 (或者,假設我正在引入一個新的團隊成員git和他們試圖運行「git pull」時他們的本地回購是「髒」。)我想知道做一個「 git拉「在這種情況下。如果不安全,可能發生的最糟糕的事情是什麼?如果我從一個可信賴的來源或不可信任的來源獲取信息,這有什麼關係?當我的工作樹和/或索引很髒時,「git pull」是否安全?
我的調查到目前爲止表明了一個混亂的想法,我認爲這是一個相當直接的問題。
首先,通過git-藏匿手冊頁使得它聽起來像git的拉動是非常安全的,如果你在一個情況下的東西可能出錯是將中止:
Pulling into a dirty tree
When you are in the middle of something, you learn that there are
upstream changes that are possibly relevant to what you are doing.
When your local changes do not conflict with the changes in the
upstream, a simple git pull will let you move forward.
However, there are cases in which your local changes do conflict
with the upstream changes, and git pull refuses to overwrite your
changes. In such a case, you can stash your changes away, perform a
pull, and then unstash, like this...
這實際上似乎到目前爲止,我的簡單測試也是如此。
也可能暗示「git pull」非常安全,Visual Studio的Git Extensions工具欄有一個突出的拉按鈕,在對「git pull」進行脫殼之前不會檢查髒物。 (如果我設計的是Visual Studio工具欄,我會盡量避免讓自己在腳下拍攝變得特別容易。)
git-pull手冊頁不會讓我的「git pull」聽起來很危險,儘管它表明這不是一個最好的做法:
If any of the remote changes overlap with local uncommitted changes,
the merge will be automatically cancelled and the work tree untouched.
It is generally best to get any local changes in working order before
pulling or stash them away with git-stash(1).
但你也可以找到建議,揪成髒是非常糟糕的,e.g.:
Avoid git-pull!
git-pull should never get invoked if you have dirty files lying around or if your branch is ahead of master.
This will always lead to some dirty artifacts in the commit history
有沒有一個簡單的答案哪個角度看是最好的,或者這在某種程度上是個案的事情?
跟進:使用「git pull --rebase」而不是「git pull」會改變答案嗎?在某些情況下,重新激活可能有它的ownpitfalls,但到目前爲止,我的猜測是,有一個髒的工作樹/索引不會使rebase更難以處理。
來自wiki的聲明是奇怪的:本地修改將從不**導致提交歷史中的「工件」。 – Cascabel 2012-03-25 06:06:27
@Jefromi:的確如此。這就是爲什麼我把重點放在後一部分(如果有必要,它會自動創建提交)。 – 2012-03-25 16:19:51
我在DeltaSpike的Wiki中看不到這樣的評論。 – 2012-04-13 20:35:56