gerrit簡版教程


設置public key

1.生成密鑰:ssh-keygen -t rsa -C "xiaoming" 
2.查看是否已經有了ssh密鑰:cd ~/.ssh

3.不知道為什么hook下面總是少個文件,需要copy個commit-msg到hook下面(最下面附上commit-msg腳本)

 

git clone ssh://xxx@gerrit.com:10101/demo.git 克隆代碼

git checkout -b branch origin/branch  將遠程branch分支檢出到本地

git init  初始化一個git倉庫

git checkout命令加上-b參數表示創建並切換,相當於以下兩條命令:

$ git branch dev $ git checkout dev


git pull 拉取最新代碼到本地

git branch 查看當前分支

git add -A 選擇所有文件提交到暫存區

git commit -m "第一次提交代碼"  提交代碼到版本庫

git push origin HEAD:refs/for/branch 提交代碼到遠程分支

git status 查詢當前分支的改動狀態

git merge dev  git merge命令用於合並指定分支到當前分支

Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
<<<<<<< HEAD Creating a new branch is quick & simple. ======= Creating a new branch is quick AND simple. >>>>>>> feature1
Git用<<<<<<<=======>>>>>>>標記出不同分支的內容,我們修改如下后保存:

git branch -d dev 刪除分支dev

git log --graph 可以查看分支合並圖

git commit --amend  可以修改提交的文案,提示沒有chanage-id的時候可以進去看看,copy個commit-msg,退出在進入便可看到chanage-id

git diff HEAD -- readme.txt  查看工作區和版本庫里面最新版本的區別

git checkout -- readme.txt  其實是用版本庫里的版本替換工作區的版本,無論工作區是修改還是刪除,都可以“一鍵還原”。

命令git checkout -- readme.txt意思就是,把readme.txt文件在工作區的修改全部撤銷,這里有兩種情況:

一種是readme.txt自修改后還沒有被放到暫存區,現在,撤銷修改就回到和版本庫一模一樣的狀態;

一種是readme.txt已經添加到暫存區后,又作了修改,現在,撤銷修改就回到添加到暫存區后的狀態。

git reset HEAD readme.txt可以把暫存區的修改撤銷掉(unstage),重新放回工作區,再輸入git checkout -- readme.txt還原文件

場景1:當你改亂了工作區某個文件的內容,想直接丟棄工作區的修改時,用命令git checkout -- file

場景2:當你不但改亂了工作區某個文件的內容,還添加到了暫存區時,想丟棄修改,分兩步,第一步用命令git reset HEAD file,就回到了場景1,第二步按場景1操作。

 

git log  查看提交記錄,結果如下

commit 292460fb714e10b152669b341e0aed77a06a8

git reset --hard 版本號(292460fb714e10b152669b341e0aed77a06a8) 回滾會丟失代碼

 git reset --soft 版本號(292460fb714e10b152669b341e0aed77a06a8) 回滾不會丟失代碼

 

git  reflog 查看版本記錄, 結果如下

e53e1ea HEAD@{2}: commit: add demo

git reset HEAD@{2}

 

GIT提交規范:

1.格式:關鍵字+正文

2.關鍵字,固定以下幾個

added(新增,簡寫add)

fixed(修復,簡寫fix)

changed(修改原來的業務邏輯,簡寫change或cg)

upgraded(優化或組件升級,簡寫upgrade或up) 

例如:“add hello world test demo”

 

#!/bin/sh
# From Gerrit Code Review 2.13
#
# Part of Gerrit Code Review (https://www.gerritcodereview.com/)
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

unset GREP_OPTIONS

CHANGE_ID_AFTER="Bug|Issue|Test|Feature|Fixes|Fixed"
MSG="$1"

# Check for, and add if missing, a unique Change-Id
#
add_ChangeId() {
clean_message=`sed -e '
/^diff --git .*/{
s///
q
}
/^Signed-off-by:/d
/^#/d
' "$MSG" | git stripspace`
if test -z "$clean_message"
then
return
fi

# Do not add Change-Id to temp commits
if echo "$clean_message" | head -1 | grep -q '^\(fixup\|squash\)!'
then
return
fi

if test "false" = "`git config --bool --get gerrit.createChangeId`"
then
return
fi

# Does Change-Id: already exist? if so, exit (no change).
if grep -i '^Change-Id:' "$MSG" >/dev/null
then
return
fi

id=`_gen_ChangeId`
T="$MSG.tmp.$$"
AWK=awk
if [ -x /usr/xpg4/bin/awk ]; then
# Solaris AWK is just too broken
AWK=/usr/xpg4/bin/awk
fi

# Get core.commentChar from git config or use default symbol
commentChar=`git config --get core.commentChar`
commentChar=${commentChar:-#}

# How this works:
# - parse the commit message as (textLine+ blankLine*)*
# - assume textLine+ to be a footer until proven otherwise
# - exception: the first block is not footer (as it is the title)
# - read textLine+ into a variable
# - then count blankLines
# - once the next textLine appears, print textLine+ blankLine* as these
# aren't footer
# - in END, the last textLine+ block is available for footer parsing
$AWK '
BEGIN {
# while we start with the assumption that textLine+
# is a footer, the first block is not.
isFooter = 0
footerComment = 0
blankLines = 0
}

# Skip lines starting with commentChar without any spaces before it.
/^'"$commentChar"'/ { next }

# Skip the line starting with the diff command and everything after it,
# up to the end of the file, assuming it is only patch data.
# If more than one line before the diff was empty, strip all but one.
/^diff --git / {
blankLines = 0
while (getline) { }
next
}

# Count blank lines outside footer comments
/^$/ && (footerComment == 0) {
blankLines++
next
}

# Catch footer comment
/^\[[a-zA-Z0-9-]+:/ && (isFooter == 1) {
footerComment = 1
}

/]$/ && (footerComment == 1) {
footerComment = 2
}

# We have a non-blank line after blank lines. Handle this.
(blankLines > 0) {
print lines
for (i = 0; i < blankLines; i++) {
print ""
}

lines = ""
blankLines = 0
isFooter = 1
footerComment = 0
}

# Detect that the current block is not the footer
(footerComment == 0) && (!/^\[?[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\//) {
isFooter = 0
}

{
# We need this information about the current last comment line
if (footerComment == 2) {
footerComment = 0
}
if (lines != "") {
lines = lines "\n";
}
lines = lines $0
}

# Footer handling:
# If the last block is considered a footer, splice in the Change-Id at the
# right place.
# Look for the right place to inject Change-Id by considering
# CHANGE_ID_AFTER. Keys listed in it (case insensitive) come first,
# then Change-Id, then everything else (eg. Signed-off-by:).
#
# Otherwise just print the last block, a new line and the Change-Id as a
# block of its own.
END {
unprinted = 1
if (isFooter == 0) {
print lines "\n"
lines = ""
}
changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
numlines = split(lines, footer, "\n")
for (line = 1; line <= numlines; line++) {
if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
unprinted = 0
print "Change-Id: I'"$id"'"
}
print footer[line]
}
if (unprinted) {
print "Change-Id: I'"$id"'"
}
}' "$MSG" > "$T" && mv "$T" "$MSG" || rm -f "$T"
}
_gen_ChangeIdInput() {
echo "tree `git write-tree`"
if parent=`git rev-parse "HEAD^0" 2>/dev/null`
then
echo "parent $parent"
fi
echo "author `git var GIT_AUTHOR_IDENT`"
echo "committer `git var GIT_COMMITTER_IDENT`"
echo
printf '%s' "$clean_message"
}
_gen_ChangeId() {
_gen_ChangeIdInput |
git hash-object -t commit --stdin
}


add_ChangeId

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM