git hooks / pre-receive - 如何在新创建的分支上获取所有提交消息?

时间:2017-11-15 06:58:46

标签: git git-branch githooks

我想在新创建的分支上获取所有提交消息(例如git log --format =%s)。我们假设我有2次提交:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#303F9F"
        android:layout_alignParentTop="true"
        android:gravity="center">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="My App Login"
            android:id="@+id/ota"
            android:textColor="#FFF"
            android:textStyle="bold"
            android:layout_gravity="center_horizontal"/>
    </RelativeLayout>

    <ScrollView
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/footer"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="15dp"
        android:layout_below="@id/header">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <TextView android:textAppearance="?android:textAppearanceSmall"
                android:gravity="bottom|left|center"
                android:id="@+id/tt5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="@string/ui"
                android:textSize="14sp"
                android:layout_below="@+id/et3"
                android:layout_weight="0.1"
                android:layout_marginTop="10dp"/>

            <EditText android:id="@+id/et4"
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="5.0dip"
                android:layout_marginBottom="5.0dip"
                android:maxLines="1"
                android:hint="Enter User Name"
                android:layout_weight="0.1"
                android:layout_below="@+id/tt5"
                android:inputType="text"/>

            <TextView android:textAppearance="?android:textAppearanceSmall"
                android:gravity="bottom|left|center"
                android:id="@+id/tt6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="@string/pw"
                android:textSize="14sp"
                android:layout_below="@+id/et4"
                android:layout_weight="0.1"
                android:layout_marginTop="10dp"/>

            <EditText android:id="@+id/et5"
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="5.0dip"
                android:layout_marginBottom="5.0dip"
                android:maxLines="1"
                android:hint="Enter Password"
                android:layout_weight="0.1"
                android:layout_below="@+id/tt6"
                android:inputType="textPassword"/>

            <Button android:id="@+id/save"
                android:layout_width="fill_parent"
                android:layout_height="0.0dip"
                android:layout_marginBottom="5.0dip"
                android:text="@string/save"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:background="@drawable/selector_btn"
                android:drawableLeft="@android:drawable/ic_menu_save"
                android:layout_weight="0.1"
                android:layout_marginTop="50dp"
                android:textColor="@color/text_white"/>

            <Button android:id="@+id/cancel"
                android:layout_width="fill_parent"
                android:layout_height="0.0dip"
                android:text="@string/cancel"
                android:textAlignment="center"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:background="@drawable/c_selector_btn"
                android:drawableLeft="@android:drawable/ic_menu_close_clear_cancel"
                android:layout_weight="0.1"
                android:textColor="@color/text_white"/>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

。使用此代码:

abcd - from yesterday
bcde - from today
旧的将是40个零,而新的将是bcde。在这种情况下,如何获取所有提交消息?

USECASE:

while read old new ref; do
    ....
done

非常感谢。

2 个答案:

答案 0 :(得分:1)

好吧,如果$ old为零,我可以使用它:

if [ $old = $z40 ]; then
    old=`$(git rev-list --boundary $newrev --not --all | sed -n 's/^-//p'`
fi

答案 1 :(得分:1)

如果我理解得很好,你想要这样的东西:

while read old new ref; do
    if [[ "${old}" =~ ^0+$ ]]; then
        range="${new}"
    else
        range="${old}..${new}"
    fi
    git log --format=%s "${range}"
done