例如我的送出曆史如下
commit 58211e7a5da5e74171e90d8b90b2f00881a48d3a
Author: test <[email protected]>
Date: Fri Sep 22 20:55:38 2017 +0800
add d.txt
commit 0fb295fe0e0276f0c81df61c4fd853b7a000bb5c
Author: test <[email protected]>
Date: Fri Sep 22 20:32:45 2017 +0800
add c.txt
commit 7753f40d892a8e0d14176a42f6e12ae0179a3210
Author: test <[email protected]>
Date: Fri Sep 22 20:31:39 2017 +0800
init
假如要删除備注為add c.txtcommit為0fb295fe0e0276f0c81df61c4fd853b7a000bb5c的這次送出
首先找到此次送出之前的一次送出的commit7753f40d892a8e0d14176a42f6e12ae0179a3210
執行如下指令
git rebase -i 7753f40
彈出如下界面
```
将0fb295f這一行前面的pick改為drop,然後按照提示儲存退出
至此已經删除了指定的commit,可以使用git log檢視下
https://zm10.sm-tc.cn/?src=l4uLj4zF0NCIiIjRzMmRitGckJLQj5CMi9DNyMo%3D&uid=795f1af4fd3eaa5ef91c5882bddbe215&hid=f358bbb5ca80da6db643212ec30bad5d&pos=2&cid=9&time=1537315867584&from=click&restype=1&pagetype=0000004000000402&bu=ss_doc&query=git+%E5%88%A0%E9%99%A4%E6%9C%80%E8%BF%91commit&mode=&v=1&uc_param_str=dnntnwvepffrgibijbprsvdsdichei
起因: 不小新把記錄了公司伺服器IP,賬号,密碼的檔案送出到了git
方法:
git reset --hard <commit_id>
git push origin HEAD --force
其他:
根據–soft –mixed –hard,會對working tree和index和HEAD進行重置:
git reset –mixed:此為預設方式,不帶任何參數的git reset,即時這種方式,它回退到某個版本,隻保留源碼,回退commit和index資訊
git reset –soft:回退到某個版本,隻回退了commit的資訊,不會恢複到index file一級。如果還要送出,直接commit即可
git reset –hard:徹底回退到某個版本,本地的源碼也會變為上一個版本的内容
HEAD 最近一個送出
HEAD^ 上一次
<commit_id> 每次commit的SHA1值. 可以用git log 看到,也可以在頁面上commit标簽頁裡找到.
commit合并:
http://www.douban.com/note/318248317/
總結:
cmds = ["git checkout -- .", "git clean -fd", "git pull"]
retcode, stdout, stderr = self.cmd.subprocess_popen(
cmd.split(" "), cwd=git_repo)
cwd設定工作目錄
git checkout -- . 點表示目前目錄,git checkout -- file則為具體檔案
删除 一些 沒有 git add 的 檔案;
git clean 參數
-n 顯示 将要 删除的 檔案 和 目錄
-f 删除 檔案,-df 删除 檔案 和 目錄
git clean -n
git clean -df
git clean -f