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

2013年11月20日 星期三

[git][cygwin] git config

Git的設定有三種層級,分別是
1. /etc/gitconfig:系統,適用所有使用者及所有repositories;git config --system [command]
2. ~/.gitconfig:使用者,適用於該使用者;git config --global [command]
3. repositories/.git/config:repositories,適用於該repositories;git config [command]

一般用第二個,給自己的帳戶使用

/home/user/.gitonfig
[user]
        name = user
        email = user@email.com
[color]
        diff = auto
        status = auto
        branch = auto
        ui = auto 
[core]
        editor = nano
        autocrlf = false

[user] name, email:name為使用git commit會儲存的name及email
[color] 如果有需要可以填
[core] editor:編輯器若沒有指定會使用系統預設的,通常是vi或vim
[core] autocrlf:在不同作業系統(ex: Windows, Linux)換行字元會不同,若設定true,它會自動切換換行字元(crlf, lf)。
在Windows我使用cygwin,作為使用git的工具,為了避免換行字元會因為不同作業系統而改變,因此我設為false,依照codebase原有的換行字元


※ ref1:http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup
※ ref2:http://huan-lin.blogspot.com/2011/05/git-coreautocrlf.html

2013年9月13日 星期五

[Gerrit][Git] 新增/刪除Branch

1). 在local端新增branch並切換

1.1). 新增branch,再切換到該branch
$ git branch [branch_name]
$ git checkout [branch_name]

1.2). 新增branch並直接切換到該branch
$ git checkout -b [branch_name]

1.2). 以某個tag為基準,新增branch並直接切換到該branch
$ git checkout [tag_name] -b [branch_name]


2). 在remote端新增branch
$ git push origin [local_branch_name]:[remote_branch_name]

3). 在local端刪除branch (-D為強制)
$ git branch -d [branch_name]
$ git branch -D [branch_name]

4). 在remote端刪除branch
$ git push origin :[branch_name]

※在Gerrit要刪除remote端的branch
在push的權限中,必須增加force push才能夠刪除

※新增branch
git branch [branch_name] [base_on_which_branch]
若是[base_on_which_branch]沒有寫,預設是master
若是此git沒有master branch,則後面沒寫會無法新增branch

2013年9月4日 星期三

[Gerrit] [Git] [Repo] 新增/刪除tag

1). 在local端新增tag
$ git tag -a [tag_name] [commit_id]

2). 在remote端新增tag
$ git push origin [tag_name]
$ git push origin --tag (一次將所有tag push上去)

3). 在local端刪除tag
 $ git tag -d [tag_name]

4). 在remote端刪除tag
$ git push origin :refs/tags/[tag_name]

//======================================

9/4新增repo的部份
在repo codebase之下的用法

1). 在local端新增tag
$ repo forall -c 'git tag [tag_name]'

2). 在remote端新增tag
$ repo forall -c 'git push --tags'

3). 在local端刪除tag
$ repo forall -c 'git tag -d [tag_name]'

4). 在remote端刪除tag(需取得gerrit權限,目前沒嘗試過)
$ repo forall -c 'git push origin :refs/tags/[tag_name]'

2013年8月26日 星期一

[Gerrit] 解決Gerrit 2.5版本以上gitweb "404 no projects found"

Gerrit 2.5版以上有即使在All-Projects設了refs/*->read:allow
Gitweb仍舊會"404 no projects found"的bug

workround
在refs/meta/config->read:allow Project Owners
取消Exclusive的勾選
雖然被設定可讀權限的人可修改project access的狀況
但會以等待review方式呈現,且無submit的權限
所以暫時可以這個方式作為workaround

※refs:http://blog.sina.com.cn/s/blog_4fb490ff01018i0v.html

2013年8月7日 星期三

[Linux][Git][Gerrit] 修改git clone codebase的名字

當從gerrit上git clone codebase時
有些server會檢查用戶name
若name不符合時則無法get code

此時可以在~/.ssh/config設置get code的名字
Hostname ip,ip,ip,ip
#若是需要設公司proxy
ProxyCommand connect -H ip.ip.ip.ip:port %h %p
User account1

EX: For gerrit
hostname ip,ip,ip,ip
port 29418
user account1

2013年4月23日 星期二

[Git] 開branch日常使用

1. 以某個tag為基礎建立新branch
$ git branch [branch_name] [tag]

2. 切換到新branch
$ git checkout [branch_name]

3. 建立檔案並打commit
$ git add
$ git commit

4. push到server (也順便在server建立此branch)
$ git push origin [local_branch_name]:[server_branch_name]
ex: git push origin v1:v1

2013年3月27日 星期三

[Git][Gerrit] 移動版本庫;從git移到gerrit


1. Gerrit先開project

2. 可看到目前遠端版本庫僅有origin
$ git remote -v

3. 在Gerrit Project中新增一個遠端版本庫git1
$ git remote add git1 ssh://git@10.109.39.56/home/git/git1.git

4. 可看到目前遠端版本庫有origin跟git1
$ git remote -v

5. 將git1的資料fetch下來
$ git fetch git1

6. 可在branch中看到remote的git1
$ git branch -a

7. 切換到master,並將remote的git1 merge進來
$ git checkout master
$ git merge git1/master

8. 上傳
$ git push

8.1 若是要將A branch push到B branch
$ git push origin [branch_a]:[branch_b]

2013年3月15日 星期五

[Git] 取消git add


當不小心將檔案git add
要取消add的指令
$ git reset HEAD [file_name]

[Git] 刪除Branch

1. 刪除local branch
$ git branch -d [branch_name]

2. 刪除local branch(強制)
當branch裡有commit,可能需要-D強制刪除branch
$  git branch -D [branch_name]

3. 刪除remote branch
$ git push origin :[branch_name]

2013年2月21日 星期四

[Gerrit][Git] path conflict的方法

Error Message:

Your change could not be merged due to a path conflict.
Please merge (or rebase) the change locally and upload the resolution for review.








紀錄,等待實驗..
http://cmc925.blogspot.tw/2011/12/your-change-could-not-be-merged-due-to.html
http://blog.csdn.net/wtysksk/article/details/8123639

--

130222 update
實驗過

1. 已經push change到gerrit
2. 在local端下git pull --rebase
3. 重新push到原有的change
$ git push ssh://[account]/[gerrit_project_path] HEAD:refs/change/[changeID]
4. 在gerrit中原有的change會顯示上了第二個patch

2013年1月9日 星期三

[git] 取消已經暫存的文件

想要取消已經git add到暫存的文件
$ git reset HEAD [filename]


Extend Reading
想要刪除server的檔案
$ git rm [filename]

2012年12月19日 星期三

[git] 開發使用指令

1). 開一個開發/測試使用branch
git branch [test_branch]

2). 移到此branch
git checkout [test_branch]

3). 在開發完後,將變更commit成一筆
git add .
git commit

4). 改壞了要回覆成codebase上的
    4.1). 全部回覆到codebase
            git checkout HEAD .
    4.2). 回覆特定資料夾
            git checkout [folder_name]

5). 紀錄此筆commit id,等等要把這筆commit剪(cherry-pick)過去master branch
git log

6). 切換到master
git checkout master

7). 把剛剛那筆commit剪過來master branch
git cherry-pick [commit-id]

8). push到codebase
git push



※ref: http://blog.luzi82.com/2010/08/git-cherry-pick-rebase.html

2012年11月9日 星期五

[git] clone裸版本庫;下載git server

下載一份git server的形式 (裸版本庫)
非codebase

git server的形式如下
/branches
/hooks
/logs
/objects
/refs
config
description
HEAD

下載:
$ git clone --bare ssh://[git server ip]

2012年11月6日 星期二

[linux][git] 架設Git Server及GitWeb

架設Git Server及GitWeb

1). 安裝ssh server、git-core、apache2、gitweb
$ sudo apt-get install ssh git-core apache2 gitweb

2). 創建放git server資料的使用者帳戶
$ sudo useradd -m -s /bin/bash [account]
$ sudo passwd [account]

※ useradd參數
-m:強制有家目錄
-s:設定shell,預設是/bin/sh


3). 啟動ssh
$ sudo sudo /etc/init.d/ssh restart

4). 創建git project
$ sudo su - [account]
$ mkdir TestProject.git
$ cd TestProject.git
$ git init --bare

5). 修改Gitweb連結路徑
$ cd /var/cache/
$ sudo rmdir git
$ sudo ln -sf [放git project的目錄路徑] git
ex: sudo ln -sf /home/git git

2012年5月7日 星期一

[git] 查看檔案修改歷程及差異

1). 檢視codebase歷程紀錄
git log

2). 檢視單隻檔案歷程紀錄
git log [file name]

3). 檢視單隻檔案歷程記錄+diff修改內容
git log -p [file name]

4). diff兩tag/commit間檔案修改內容
git diff [tag1/commit1]:[path/filename] [tag2/commit2]:[path/filename]

※範例
git diff be6a33b6087d5ab1de711774bcdbbf55bfd45785:vendor/si/build.sh e19a487ccaecb10fda12676e4370389241875bd4:vendor/si/build.sh

2012年4月24日 星期二

[git] 合併patch到codebase

patch有許多format,若拿到的patch無法用git am合併
則選擇用其他的指令

1). patch (僅可以合併單筆patch)
patch -p1 < [patch路徑及檔名]

2). git am (可合併單筆也可合併資料夾內所有patch)
git am [patch路徑及檔名]

3). 刪除git am先前所有合併patch的紀錄
git am --abort

2012年3月14日 星期三

[Linux] [git] 限制帳號對主機shell

在主機建立一個帳號專放git project
容許其他人從這台主機get code
但限制其帳號只能用ssh連接git,無法對主機shell

1). 修改passwd檔
sudo vi /etc/passwd
2). 更改git帳號的權限
git:x:1000:1000::/home/git:/usr/bin/git-shell

※備註:
更改後shell進去的畫面:
$ ssh git@gitserver
fatal: What do you think I am? A shell?
Connection to gitserver closed.

2012年2月20日 星期一

[Git] commit template

1). commit的template
git config --global commit.template [檔案名]
ex: git config --global commit.template ~/.git_template

※應用:
1). script: 將template寫在一隻檔案,並設定git config
#!/bin/sh

### function define ###

git_template()
{
cat << EOF > ~/.git_template
[Topic]:
[Release Note]:
[Involve]:
[Comments]:
EOF
}

### entry point ###

git_template

git config --global commit.template ~/.git_template

2012年1月17日 星期二

[Git] 刪除commit

1). 將狀態回覆到HEAD前,commit刪掉、資料也回復到原本
git reset --hard HEAD^

1). 僅commit回覆到HEAD前,資料不會變更
git reset --soft HEAD^