get_origin_all显示本目录下所有项目git地址
#!/bin/sh
## get_origin_all.sh
##This bash file can update all git project in given directory
#in case this file being invoked form other path
base_dir=$(dirname "$0")
#a tool script for colorful output
cd $base_dir
#read given directory as repositories directory,
#or current directory
project_dir="."
if [ ! -z $1 ]
then
project_dir=$1
fi
if [ ! -d $project_dir ]
then
echo "$project_dir is not a directory."
exit 1
fi
echo "Set repository base directory to $project_dir"
for project in `ls $project_dir`
do
if [ -d $project ]
then
cd $project
#update git repository
if [ -d '.git' ]
then
#echo "Updating project:$project"
#git pull
git remote show origin|grep Fetch
#echo "Done."
echo
#update svn repository
elif [ -d '.svn' ]
then
echo "Updating project:$project"
svn update
echo "Done."
echo
else
echo "$project is not a repository.\n"
fi
cd ..
fi
done
echo "Finished..."
read
exit 0
git_pull_all本目录下所有项目git pull
#!/bin/sh
## git_pull_all.sh
##This bash file can update all git project in given directory
#in case this file being invoked form other path
base_dir=$(dirname "$0")
#a tool script for colorful output
cd $base_dir
#read given directory as repositories directory,
#or current directory
project_dir="."
if [ ! -z $1 ]
then
project_dir=$1
fi
if [ ! -d $project_dir ]
then
echo "$project_dir is not a directory."
exit 1
fi
echo "Set repository base directory to $project_dir"
for project in `ls $project_dir`
do
if [ -d $project ]
then
cd $project
#update git repository
if [ -d '.git' ]
then
echo "Updating project:$project"
git pull
echo "Done."
echo
#update svn repository
elif [ -d '.svn' ]
then
echo "Updating project:$project"
svn update
echo "Done."
echo
else
echo "$project is not a repository.\n"
fi
cd ..
fi
done
exit 0
clone_all按git地址列表批量clone项目到本地
#!/bin/sh
## clone_all.sh
echo "Start..."
git clone ssh://git@git.example.com/Test1.git
git clone ssh://git@git.example.com/Test2.git
echo "Finished..."
read
exit 0
commmit, push, tag
# commmit, push and tag
#!/bin/sh
echo "====== begin"
repo="D:\git\foo"
if [ -d $repo ]; then
cd $repo
pwd
echo "---- cur status"
git status
echo
echo -e "\n\n input commit msg:"
read msg
git commit -am msg
git push
echo -e "\n\n---- tag when input y?"
read y
if [[ "$y" == "y" ]]; then
echo -e "\n tag list:"
git tag
tag_prefix=release_$(date +%Y%m%d)
echo -e "\n--tag_prefix:${tag_prefix},input suffix:"
read tag_suffix
tag=$tag_prefix$tag_suffix
echo "\n--begin tag: $tag"
git tag $tag
git push origin $tag
echo "\n--end tag: $tag"
fi
echo "done."
echo
else
echo "Repo not found: $repo"
fi
echo "====== all done."
echo "enter to exit"
read
diff和patch的使用示例
diff a.txt b.txt > some.patch
patch a.txt some.patch
#pathc之后将会使两者(a.txt和b.txt)一致
diff两个文件,结果显示46a47,48,可理解为:
1)46:第一个文件(或旧文件)的行号,表示差异开始的位置。
2)a:操作类型,这里是 “add”(添加),表示需要在第一个文件的第46行后添加内容。
3)47,48:第二个文件(或新文件)的行号范围,表示需要添加的内容来自新文件的第47到48行。
总体意思是:你需要将第二个文件的第47-48行内容,添加到第一个文件的第46行之后,才能使两者一致。
a:add, d:delete, c: change