顯示具有 git 標籤的文章。 顯示所有文章
顯示具有 git 標籤的文章。 顯示所有文章

2016年4月6日 星期三

default git email

這次建新的 repository 又忘了改 email... ~/.gitconfig 裡的 user email 是預設值 查了一下可以用

[user]
 name = Elvis Chiang
# email = email@default.one
 useConfigOnly = true

這樣每次使用新的 repository 時就會提醒你設定新的 email

git config user.email hello@github.com

Github 上已經上傳的 commit 可以使用官方提供的 script

Changing author info

原來的 repository 只要重新 git pull --rebase 就好

2014年11月10日 星期一

git shallow clone

shallow clone

參考這篇作法 How to handle big repositories with git

git clone --depth depth remote-url

另外 repo 也可以

repo init --depth=DEPTH

unshallow

參考 Convert shallow clone to full clone

git fetch --unshallow

2014年1月8日 星期三

不小心 git commit --amend 了別人的 patch

環境

2d14654 HEAD@{0}: commit (amend): Other's patch
428555b HEAD@{1}: commit: Other's patch
bd33767 HEAD@{2}: commit: Previous one

先把 HEAD 退回到原來的 patch, 記得確定把你的 working directory 搞乾淨

$ git reset --hard HEAD~1
HEAD is now at bd33767 Previous one

$ git cherry-pick 428555b
....

把 amend 到別人 patch 的內容 diff 出來,重新 apply, apply 的參數 - (dash) 表示是從 STDIN 讀入

$ git diff 428555b 2d14654 | git apply -

這時打 git status 就可以發現當初的修改回來 unstage 的狀態了, 重新 git commit

$ git commit

完成

2013年9月17日 星期二

一些 git / gerrit / ssh 設定

git / gerrit

alias

常用的指令例如 status 可以減化成短指令

~/.gitconfig

[alias]  
    ci = commit  
    st = status  
    co = checkout  
    l = log --stat=140,100  
    br = branch  
    p = cherry-pick  
    r = rebase  
    f = fetch  
    up = pull --rebase  

指令就變為

$ git st

自動產生 Change-Id

單獨 git clone 下來的 git repository 不會有 commit-msg hook
所以 push 到 gerrit 時,不會有 Change-Id
沒有 Change-Id 的話,重複 push 不會在同一個 patch 裡繼續疊加
所以 commit-msg hook 是必需要用的
(除非要手動從 gerrit 上 copy 下來...何苦呢...)

如果手邊有 BSP

    $ find . -name commit-msg \<BSP_ROOT>/.repo

把他 copy 到 .git/hooks/ 裡

gerrit server

    $ scp -p -P 29418 \<SERVER>:hooks/commit-msg .git/hooks/

template

每次 git repository commit 時,如果要填寫固定格式
可以先將文字檔存下來,就不會每次都要打一次

per repository

進 git repository 寫一個文字檔 .gittemplate

$ git config commit.template=.gittemplate

global

放在 ~/.gitconfig 裡指定

[commit]  
    template = ~/.gittemplate

手動 push 到指定的 branch

$ git push ssh://\<SERVER>:29418/\<PATH> HEAD:refs/for/\<BRANCH>

PATH 可以使用

$ git config -l | grep url remote.origin.url=ssh://\<SERVER>:29418/here/is/my/branch

在此可以知道路徑是 here/is/my/branch

BRANCH

$ git branch -a
...
remotes/origin/aosp/jb-release
...

在裡面找需要的 branch, 不需要包 remotes/origin
所以這邊需要 aosp/jb-release

$ git push ssh://mickey.acer.com.tw:29418/here/is/my/branch HEAD:refs/for/aosp/jb-release

ssh

設定 gerrit

為了不要每次下指令都指定 user name 也就是

$ repo init -u ssh://my.id@\<SERVER>...... 

~/.ssh/config

Host \<SERVER>
Port 29418
User XXXX.YYY

跟 Gerrit 裡 Settings -> Profile -> Username 一樣

2013年8月30日 星期五

使用 Dropbox 備份 source code

基本上我自己開發 sample app 都會一併使用 git 開始管理 source code
一方面為了備份, 只是存在本地總是有風險

Steps

  • 聯結 Dropbox 到電腦
    我的路徑是 ~/Dropbox/ git base 想放在 ~/Dropbox/Backup/gitbase
  • 建立 bare 的 git repository
    bare 的話,就不會把 source code 再 checkout 出來一份
$ cd ~/Dropbox/Backup/gitbase
$ git init --bare HelloWorld
Initialized empty Git repository in /Users/elvis/Dropbox/Backup/gitbase/HelloWorld/
脫光光的 git repository 長得像
$ ls -l HelloWorld
total 24
drwxr-xr-x 9 elvis staff 306 8 30 14:56 .
drwxr-xr-x 8 elvis staff 272 8 30 14:56 ..
-rw-r--r-- 1 elvis staff 23 8 30 14:56 HEAD
-rw-r--r-- 1 elvis staff 112 8 30 14:56 config
-rw-r--r-- 1 elvis staff 73 8 30 14:56 description
drwxr-xr-x 11 elvis staff 374 8 30 14:56 hooks
drwxr-xr-x 3 elvis staff 102 8 30 14:56 info
drwxr-xr-x 4 elvis staff 136 8 30 14:56 objects
drwxr-xr-x 4 elvis staff 136 8 30 14:56 refs
  • 連結原來的 source code 到 dropbox
$ cd ~/work/HelloWorld
$ git remote add dropbox ~/Dropbox/Backup/gitbase/HelloWorld
如果原來已經有一個 master 了, 你也本來沒有 upstream
$ git push dropbox master
$ git branch -u dropbox/master master
如果原來的 master 已經有 upstream 了,只是備份用,就直接
git push dropbox master