git 學習
1. git clone 分支
git clone -b dev-i386 [email protected]:Jiangxumin/my_apt-get-iinstall.git
2. git查詢
git log --pretty=format:"%h--%an --%ar:%s" | grep jiang_xmin
選項 | 說明 |
---|---|
%H | 提交對象(commit)的完整哈希字串 |
%h | 提交對象的簡短哈希字串 |
%T | 樹對象(tree)的完整哈希字串 |
%t | 樹對象的簡短哈希字串 |
%P | 父對象(parent)的完整哈希字串 |
%p | 父對象的簡短哈希字串 |
%an | 作者(author)的名字 |
%ae | 作者的電子郵件地址 |
%ad | 作者修訂日期(可以用 -date= 選項定製格式) |
%ar | 作者修訂日期,按多久以前的方式顯示 |
%cn | 提交者(committer)的名字 |
%ce | 提交者的電子郵件地址 |
%cd | 提交日期 |
%cr | 提交日期,按多久以前的方式顯示 |
%s | 提交說明 |
3. git 刪除未提交 文件
# 刪除 untracked files
git clean -f
# 連 untracked 的目錄也一起刪掉
git clean -fd
# 連 gitignore 的untrack 文件/目錄也一起刪掉 (慎用,一般這個是用來刪掉編譯出來的 .o之類的文件用的)
git clean -xfd
查詢 那些文件未提交文件,會被刪除
# 在用上述 git clean 前,牆裂建議加上 -n 參數來先查詢會刪掉哪些文件,防止重要文件被誤刪
git clean -nxfd
git clean -nf
git clean -nfd
4. 將git協議 由https修改爲ssh
由於https, 每次git push的時候每次都要輸入用戶名密碼,對於每一個追求高效的程序員來說,簡直就是 shit 。直接將git 協議爲ssh 就可以了了.
修改 config 文件: vim .git/config
如圖將 .git/config 文件, remote “origin” 下的 url 修改爲 ssh 就可以了.
前提, 必須將本機的 ssh公鑰,添加到github上.
5. 回退單個文件到某一次次提交
git checkout 1831e5f5262c1ac0d63e8458dcad06b6af64bbd8 src/vm/download.py
6. Https方式使用Git@OSC設置密碼
https方式每次都要輸入密碼,按照如下設置即可輸入一次就不用再手輸入密碼的困擾而且又享受https帶來的極速
設置記住密碼(默認15分鐘):
git config --global credential.helper cache
如果想自己設置時間,可以這樣做:
git config credential.helper 'cache --timeout=3600'
這樣就設置一個小時之後失效
長期存儲密碼:
git config --global credential.helper store
增加遠程地址的時候帶上密碼也是可以的。(推薦)
http://yourname:[email protected]/name/project.git
補充:使用客戶端也可以存儲密碼的。
如果你正在使用ssh而且想體驗https帶來的高速,那麼你可以這樣做:
切換到項目目錄下 :
cd projectfile/
移除遠程ssh方式的倉庫地址
git remote rm origin
增加https遠程倉庫地址
git remote add origin http://yourname:[email protected]/name/project.git
6. git config配置文件
配置當前倉儲 .git/config :
$ git config --local -e
配置全局編輯器
$ git config --global core.editor vim
檢查你的設置
$ git config --list
user.name=jxm_zn
[email protected]
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
core.editor=vim
...
查看user.naem
$ git config user.name
jinag_xmin
$git config --global user.name
jxm_zn
$git config --local user.name
jinag_xmin