Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Tuesday, February 07, 2017

[轉] 關於refs/for/

資料來源: http://lishicongli.blog.163.com/blog/static/146825902013213439500/

1. 這個不是git的規則,而是gerrit的規則,
2. Branches, remote-tracking branches, and tags等等都是對commite的引用(reference),引用都以 「refs/……」表示. 比如remote branch: origin/git_int(=refs/remotes/origin/git_int), local tag: v2.0(=refs/tags/v2.0), local branch: git_int(=refs/heads/git_int)…
3. 簡單點說,就是refs/for/mybranch需要經過code review之後才可以提交;refs/heads/mybranch不需要code review。

(since you want to directly push into the branch, rather than create code reviews. Pushing to refs/for/* creates code reviews which must be approved and then submitted. Pushing to refs/heads/* bypasses review entirely, and just enters the commits directly into the branch. The latter does not check committer identity, making it appropriate for importing past project history)
如果需要code review,直接push
$git push origin master
那麼就會有「! [remote rejected] master -> master (prohibited by Gerrit)」的錯誤信息
而這樣push就沒有問題,
$git push origin HEAD:refs/for/mybranch

下面一段是對「refs/for」更詳細的描述:
The documentation for Gerrit explains that you push to the "magical refs/for/'branch' ref using any Git client tool".



This image is taken from the Intro to Gerrit. When you push to Gerrit, you do git push gerrit HEAD:refs/for/. This pushes your changes to the staging area (in the diagram, "Pending Changes"). Gerrit doesn't actually have a branch called ; it lies to the git client.
Internally, Gerrit has it's own implementation for the Git and SSH stacks. This allows it to provide the "magical" refs/for/ refs.
When a push request is received to create a ref in one of these namespaces Gerrit performs its own logic to update the database, and then lies to the client about the result of the operation. A successful result causes the client to believe that Gerrit has created the ref, but in reality Gerrit hasn't created the ref at all.
After a successful patch (i.e, the patch has been pushed to Gerrit, [putting it into the "Pending Changes" staging area], reviewed, and the review has passed), Gerrit pushes the change from the "Pending Changes" into the "Authoritative Repository", calculating which branch to push it into based on the magic it did when you pushed to refs/for/. This way, successfully reviewed patches can be pulled directly from the correct branches of the Authoritative Repository.

Wednesday, September 24, 2014

git 打包的一个bash 函数


資料來源: http://blog.csdn.net/free2o/article/details/3981786




Here is my bash alias. The argument is the <branch name> to export.
An example:

    cd /path/to/foo/
    _gittar master

The output is (time in ISO 8601 / UTC):

    ../foot-YYYYMMDD.HHMM.tar.gz

function _gittar ()
{
    local name=$(pwd)
    name=${name##*/}

    if [ ! "$1" ]; then
        echo "[ERROR] what branch to export?"
        return 1
    fi

    local date=$(TZ=UTC date '+%Y%m%d.%H%M')
    local pkg="$name-$date"
    local dir=".."
    local tar="$dir/$pkg.tar.gz"

    git archive /
        --format=tar /
        --prefix="$pkg/" /
        "$@" |
    gzip --best > "$tar"

    echo $tar
}

Friday, April 18, 2014

repo 的用法

資料來源: http://blog.csdn.net/free2o/article/details/3981588

  1. 下載 repo 的地址: http://android.git.kernel.org/repo ,可以用 wget http://android.git.kernel.org/repo 或者 curl http://android.git.kernel.org/repo >~/bin/repo  來下載 repo , chmod a+x ~/bin/repo
  2. 用repo sync 在抓去 android source code 的時候,會經常出現一些錯誤導致 repo sync 中斷,每次都要手動開始。 可以用如下的命令,來自動重複:   $?=1;   while [ $? -ne 0 ] ; do  repo sync ; done
  3.  repo help [ command ] , 顯示command 的詳細的幫助信息內容
  4. repo init -u URL ,  在當前目錄安裝 repository ,會在當前目錄創建一個目錄 ".repo"  -u 參數指定一個URL, 從這個URL 中取得repository 的 manifest 文件。   repo init -u git://android.git.kernel.org/platform/manifest.git
               可以用 -m 參數來選擇 repository 中的某一個特定的 manifest 文件,如果不具體指定,那麼表示為默認的 namifest 文件 (default.xml)    repo init -u git://android.git.kernel.org/platform/manifest.git -m dalvik-plus.xml
              可以用 -b 參數來指定某個manifest 分支。
               repo init -u git://android.git.kernel.org/platform/manifest.git -b release-1.0
              可以用命令: repo help init 來獲取 repo init 的其他用法
        4. repo sync [project-list]
            下載最新本地工作文件,更新成功,這本地文件和repository 中的代碼是一樣的。 可以指定需要更新的project , 如果不指定任何參數,會同步整個所有的項目。
           如果是第一次運行 repo sync , 則這個命令相當於 git clone ,會把 repository 中的所有內容都拷貝到本地。 如果不是第一次運行 repo sync , 則相當於 git remote update ;  git rebase origin/branch .  repo sync 會更新 .repo 下面的文件。 如果在merge 的過程中出現衝突, 這需要手動運行  git  rebase --continue
      5. repo update[ project-list ]
      上傳修改的代碼 ,如果你本地的代碼有所修改,那麼在運行 repo sync 的時候,會提示你上傳修改的代碼,所有修改的代碼分支會上傳到 Gerrit (基於web 的代碼review 系統), Gerrit 受到上傳的代碼,會轉換為一個個變更,從而可以讓人們來review 修改的代碼。
       6. repo diff [ project-list ]
        顯示提交的代碼和當前工作目錄代碼之間的差異。
       7. repo download  target revision
        下載特定的修改版本到本地, 例如:  repo download pltform/frameworks/base 1241 下載修改版本為 1241 的代碼
       8. repo start newbranchname
        創建新的branch分支。 "." 代表當前工作的branch 分支。
       9.  repo prune [project list]
        刪除已經merge 的 project
      10. repo foreach [ project-lists] -c command
       對每一個 project 運行 command 命令
      11. repo status
       顯示 project 的狀態

Monday, January 16, 2012

Git - How to use .netrc file on windows to save user and password

Reference: Git - How to use .netrc file on windows to save user and password


Is it possible to use a .netrc file on windows when I'm using Git to clone a remote repository with http and user - password?


Answer:

You must define:
  • environment variable %HOME%
  • put a _netrc file in %HOME%
If you are using Windows 7
run the cmd type this:
setx HOME %USERPROFILE%
and the %HOME% will be set to 'C:\Users\"username"'
then go to it and make a file called '_netrc'
Note: for Windows, you need a '_netrc' file, not a '.netrc'.
Its content is quite standard:
machine hostname1
login login1
password password1
machine hostname2
login login2
password password2

How to apply `git diff` patch?

Reference: How to apply `git diff` patch?
How can my client apply patch created by git diff without git installed? I have tried to use patchcommand but it always asks file name to patch.


Answer:
1. git diff --no-prefix > patchfile, patch -p0 < patchfile
2. git apply file.diff
3. git diff > patchfile, patch -p1 < patchfile