如果改動了working area和staging area的檔案,需要儲存起來,然後忽略這些改動,回到最後一次提交的狀態。可以使用git stash.
假定項目中有一個檔案t,先用git rm t 從刪除之,這時候working area中該檔案消失了。
然後執行git stash命令,再看working area中,該檔案又回來了。
這時候調用git stash list命令,看到:
git stash liststash@{0}: WIP on master: 1c47165 change package name
這次的改動沒有徹底丟掉,而是被儲存到stash list中。可以認為是擱置爭議,保留個人意見,雖然服從了大局,但是個人的意見還是存在了一個stash list的地方,以後隨時可以拿出來。
拿出來的話,用git stash pop,
Removing t# On branch master# Changes not staged for commit:# (use "git add/rm <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)##deleted: t## Untracked files:# (use "git add <file>..." to include in what will be committed)##deploy.tar.bz2no changes added to commit (use "git add" and/or "git commit -a")Dropped refs/stash@{0} (8e32484d1da7ab8e47986e1aff39a5711087dcc2)
結果可以看到,又回到我用git rm刪除t檔案的狀態。