[問題] git 新手的問題 有關分支中刪除檔案

看板Linux作者 (海獅)時間11年前 (2013/01/30 10:06), 編輯推噓0(0015)
留言15則, 5人參與, 最新討論串1/1
最近開始學習git 但有點搞不懂他對分支中刪除檔案的定義 我原本在 master 把一個檔案加入追蹤 ( git add test.txt ) 然後commit ( git commit -m "master" ) 接著創建並切換到分支 develop ( git checkout -b develop master ) 然後在develop中刪掉這個檔案 ( rm test.txt ) 這時候如果我不做其他事情就切換回 master ( git checkuot master ) 發現master的 text.txt檔案也被砍了!? 即使我先在develop做了commit ( git commit -m "delete test" ) 然後再切換回master 也一樣該檔案不見 --- 我看教學上的想法是所有在develop裡面做的更動 直到我回master下git merge指令前,都不會動到master裡面的東西 請問是我的想法錯了嗎? 還是我的指令下的不對呢 -- Insanity is doing the same thing over and over again while expecting a different outcome. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.61.45

01/30 10:14, , 1F
在master加入檔案以後要commit吧?
01/30 10:14, 1F

01/30 10:58, , 2F
啊真的忘了 但試過了還是無效QQ 我改一下原文感謝
01/30 10:58, 2F
※ 編輯: BBSealion 來自: 220.133.61.45 (01/30 11:00)

01/30 11:29, , 3F
rm也要commit
01/30 11:29, 3F

01/30 12:29, , 4F
有耶 後半段就是嘗試rm完之後commit再跳回去 還是消失
01/30 12:29, 4F

01/30 14:32, , 5F
我測試結果是你預期的情形, 你重開一個 git repo 測試看看
01/30 14:32, 5F

01/30 15:48, , 6F
commit前用git status看一下,rm不會把刪除的動作納入
01/30 15:48, 6F

01/30 15:48, , 7F
下次commit,除非你用commit -a,用git rm才會納入
01/30 15:48, 7F

01/30 15:49, , 8F
你的刪除動作沒被commit進去,所以你切換branch的時候
01/30 15:49, 8F

01/30 15:50, , 9F
只是讓這個刪除的動作rebase到另一個branch上而已
01/30 15:50, 9F

01/30 15:50, , 10F
或是不要用git commit -m,也可以看到哪些變動會被commit
01/30 15:50, 10F

01/30 21:33, , 11F
喔真的耶 用git rm就是我想要的狀況了 但這表示要小心
01/30 21:33, 11F

01/30 21:33, , 12F
不能隨便rm 不然就會誤刪到其他分支的檔案嗎 這樣感覺
01/30 21:33, 12F

01/30 21:33, , 13F
超危險的orz....
01/30 21:33, 13F

01/31 12:06, , 14F
不小心刪錯只要回 master 然後 git checkout -- 檔案名
01/31 12:06, 14F

01/31 12:06, , 15F
就會回來了
01/31 12:06, 15F
文章代碼(AID): #1H280EV2 (Linux)