在recent answer中,他詳細介紹了git-reset
的三種最常用的選項(--hard
,--mixed
和--soft
)的典型應用案例,torek提到順便指出git-reset
還提供了兩個比較深奧的標誌,稱爲--merge
和--keep
。該git-reset
man page介紹這兩個標誌如下:什麼是git-reset的--merge和--keep標誌的典型用例?
--merge Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between <commit> and the index has unstaged changes, reset is aborted. In other words, --merge does something like a git read-tree -u -m <commit>, but carries forward unmerged index entries. --keep Resets index entries and updates files in the working tree that are different between <commit> and HEAD. If a file that is different between <commit> and HEAD has local changes, reset is aborted.
我完全理解時使用--hard
,--mixed
,或--soft
,但我只瞭解到--merge
和--keep
一邊讀託雷克的答案存在,我可以沒有想到這兩個標誌的實際使用情況......你通常在什麼情況下使用這兩個標誌?
我主要是在尋找簡單英文的解釋。就拿this answer by VonC下面這段文字,它闡明瞭git reset --soft
一個典型的使用情況下,作爲一種模式:
[...]每次:
- 你滿意,你到底是什麼了(在工作樹和索引項)
- 你是不是滿意,所有的帶你到那裏的提交:
git reset --soft
就是答案。
但是,我並沒有避免對這些標誌進行一點實驗,這與我在this answer of mine中發佈的愚蠢購物清單示例的精神類似。
在你的例子中,如果你從'git reset --keep fix-bug-1234'切換時編輯'buggy-file.c',如果'buggy-file.c'不同在分支'devel'和分支'fix-buf-1234'中。因此,'--merge'。 – 2014-08-28 22:49:11
@DietrichEpp:但是在這種情況下,索引和''(它在'devel'與'release'的不同之處)'中的'--merge':'buggy-file.c' * *它已經進行了暫時的更改(我們修改了工作樹),所以'git reset --merge'也會中止重置。我有感覺在手冊頁描述中有些東西沒有出現。源代碼指出'--merge'被允許在衝突合併的中間,而' - soft'和'--keep'不是。 –
torek
2014-08-28 23:20:56
@torek謝謝你。不過,這些標誌對我來說依然非常奇特。如果我覺得有必要使用它們,我可能會回到這裏並發表我自己的答案。 – Jubobs 2014-09-01 17:05:59