用户工具

站点工具


linux:git
  • 协议支持
git://xlongwei.com/sample.git     //需要后台运行git-daemon
http://git.xlongwei.com/git/sample.git  //git update-server-info,需要nginx转发,http://git.xlongwei.com/git/
gituser@xlongwei.com:/soft/gitrepos/sample.git  //需要密码或密钥;hooks/post-update自动执行git update-server-info
git@xlongwei.com:testing.git   //使用gitolite-admin进行权限控制
  • fork
git clone your-fork-url
git remote add upstream origin-author-url
git branch -av # 查看所有分支
git checkout -b name upstream/master # 检出远程分支
git push gitee HEAD:master  # 强制推送:-u -f 覆盖本地:git reset --hard origin/master
git reflog,git reset --hard {commitId}  #git merge之后回退

  • 多仓库推送
# git remote set-url --add gitee git@gitee.com:xlongwei/confluence.git
# git remote -v,新加的仓库只有push没有pull,一次push就可以推送到多个仓库
gitee git@gitee.com:xlongwei/confluence.git (push)
# vi .git/config,手动添加行,与上面效果相同
url = git@gitee.com:xlongwei/confluence.git
# 批量拉取子目录
for dir in `ls`; do cd $dir && git pull && cd ..; done
  • 多分支管理
git checkout -b test # 创建新分支
git remote add gitee https://gitee.com/xlongwei/test.git # 添加远程仓库
git fetch --all # 获取远程仓库
git reset --hard origin/master  # 重置本地内容为远程分支
git push gitee test:test # 推送test分支到远程仓库
  • 定时发版
cd /soft/gitdata/sample
lines=`git pull origin master|wc -l`
if [ $lines -gt 2 ] ; then
echo "redeploy dev"
else
echo "nothing change"
fi
  • 假设未更改
git update-index --assume-unchanged /path/to/file
git update-index --no-assume-unchanged restart.sh
git stash  #保存现场,因冲突而不能拉取最新
git pull   #拉取最新
git stash pop  #恢复现场,处理冲突
git stash drop  #丢弃修改
git reset --hard FETCH_HEAD  #放弃本地修改,使用fetch head覆盖
git branch -f master HEAD,git checkout master #出现detached from master时,强制修改master,并切回master分支
git fetch
git checkout FETCH_HEAD path
  • 稀疏克隆
git clone git@xlongwei.com:cc --no-checkout -depth 1
git config core.sparseCheckout true
echo "cc-ui" > .git/info/sparse-checkout
git checkout master
  • 常用命令
git config --global credential.helper store  #记住密码
git config --system --unset credential.helper # 清除密码
git log -3 --stat  #查看最近3次提交的文件变化列表
git log -p  #查看最近提交的文件内容变化情况
git diff commit-id-1 commit-id-2 -p  #比较某两次提交的文件内容变化情况
git log | grep "^Author: " | awk '{print $2}' | sort | uniq -c | sort -k1,1nr # 统计作者提交数
git log --author=yourname --since="2014-07-01" --no-merges | grep -e 'commit [a-zA-Z0-9]*' | wc -l # 限制月份until
git log --author="_your_name_" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' - # 统计代码量
git init
git remote add origin https://gitee.com/xlongwei/logserver-spring-boot-starter.git
git pull origin master --allow-unrelated-histories  //master->fatal: branch ‘master’ does not exist
git branch --set-upstream-to=origin/master master
git format-patch from-commit-id // 从commit-id开始,到最新的提交,生成差异文件,多个文件打包发送
git am < 0001.patch // git apply --stats dir/*.patch
git flow init   //配置分支命名规则:master develop feature release hotfix
git flow feature start rss-feed   //开始新特性开发,创建新分支feature/rss-feed并切换
git flow feature finish rss-feed  //完成特性开发,回到develop分支,合并特性分支,删除特性分支  
git flow release start 1.1.5   //创建release分支,可以对某些文件进行最后的修改,如pom.xml
git flow release finish 1.1.5  //合并到master和develop,删除release分支,回到develop分支;master提交可能触发自动部署
git flow hotfix start missing-link  //创建热修复分支hotfix/missing-link
git flow hotfix finish missing-link  //非常类似发布版本,合并到master和develop,删除hotfix,回到develop
  1. master: 只能合并其他分支代码,不能直接提交代码到master分支
  2. develop: 是其他开发分支的基础,汇集所有已经完成的功能,并等待整合到master分支

  1. feature/rss-feed:功能开发分支,完成后被删除
  2. hotfix/missing-link:热修复分支,完成后被删除

  • 端口号更改
vi ~/.ssh/config
port 37122
git svn clone svn://xlongwei.com/xlongwei/wxapp
git svn rebase  //相当于svn up
git svn dcommit //相当于svn commit,需要先更新
git config --global core.hooksPath /home/jenkins/hooks  #或/usr/share/git-core/templates/hooks
  • 脚本命令
vi ~/.profile
keyson(){
  eval $(ssh-agent -s)
  ssh-add ~/.ssh/xlongwei.git
}
keysoff(){
  kill `ps -ef|grep ssh-agent|awk '{print $2}'`
}
parse_url() {
  eval $(echo "$1" | sed -e "s#^\(\(.*\)://\)\?\(\([^:@]*\)\(:\(.*\)\)\?@\)\?\([^/?]*\)\(/\(.*\)\)\?#${PREFIX:-URL_}SCHEME='\2' ${PREFIX:-URL_}USER='\4' ${PREFIX:-URL_}PASSWORD='\6' ${PREFIX:-URL_}HOST='\7' ${PREFIX:-URL_}PATH='\9'#")
}
gitc(){
  if [ "$1" == "" ]; then
    echo "gitc url"
  else
    URL=${1:-"http://user:pass@example.com/path/somewhere"}
    PREFIX="URL_" parse_url "$URL"
    #echo "$URL_SCHEME://$URL_USER:$URL_PASSWORD@$URL_HOST/$URL_PATH"
    echo "git clone $1 $URL_PATH"
    git clone $1 /d/OpenSources/$URL_PATH
  fi
}
jdk8(){
  export PATH="/c/Program Files/Java/jdk1.8.0_92/bin":$PATH
  export JAVA_HOME="/c/Program Files/Java/jdk1.8.0_92"
}
jdk11(){
  export PATH="/c/Program Files/Java/jdk-11.0.2/bin":$PATH
  export JAVA_HOME="/c/Program Files/Java/jdk-11.0.2"
}
linux/git.txt · 最后更改: 2022/07/01 08:38 由 admin