[git newbie] 假設我正在處理一個新檔案并且我寫了一個故事:
Version1: A guy walks into a bar
[here I tell my story]
在這一點上,我喜歡我寫的東西,但我想做一些改變,所以我把我的改變藏起來:
$git stash save -u 'version1: a guy walks'
資訊:
Saved working directory and index state On dev_story: version1: a guy walks
現在我改變它:
Version2: A nice dude walks into a bar
[here I tell a slighly different story]
并再次藏起來:
$git stash save -u 'version2: a dude walks'
資訊:
Saved working directory and index state On dev_story: version2: a dude walks
檢查我的藏匿清單,我看到:
$ git stash list
stash@{0}: On dev_story: version2: a dude walks
stash@{1}: On dev_story: version1: a guy walks
我想向朋友展示我的作品并辯論版本 1 與版本 2。
當我嘗試應用 stash@{0} 時,它沒有顯示“一個人走路......”我試過的內容:
$ git stash show stash@{0} //new line no error
$ git stash apply stash@{0}
test/story.txt already exists, no checkout
error: could not restore untracked files from stash
uj5u.com熱心網友回復:
$ git stash show stash@{0} //換行沒有錯誤
Git 在這里沒有顯示任何內容,因為您的檔案未被跟蹤。git stash show不會向您顯示未跟蹤的檔案,除非您使用-u.
$ git stash show -u stash@{0}
test/story.txt | 1
1 file changed, 1 insertion( )
$ git stash show -u -p stash@{0}
diff --git a/test/story.txt b/test/story.txt
new file mode 100644
index 0000000..f5d91d3
--- /dev/null
b/test/story.txt
@@ -0,0 1 @@
A nice dude walks into a bar
$ git stash apply stash@{0} test/story.txt already exists, no checkout error: could not restore untracked files from stash
您已經有了一個包含更改的 test/story.txt 檔案。因為您隱藏的更改會創建一個新檔案,所以 git 會保護您不被它覆寫現有的 test/story.txt。
有關藏品的更多資訊,請參見藏品和清潔。
總的來說,我發現藏匿處很容易變得凌亂并且忘記里面有什么或它適用于什么。暫時隱藏更改很有用。對于更長的時間,我建議使用提交和分支。
如果您需要保存一些未完成的作業,請提交并將其記錄為“wip”(進行中的作業)。然后稍后修改提交(請參閱更改上次提交。如果你想要兩個不同的版本,請創建一個分支;這就是他們擅長的。分支非常便宜。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/536309.html
上一篇:Github回購結構建議
