Git

全局变量
git config --global user.name "zhangsan"            设置用户名
git config --global user.email  "zhangsan@qq.com"   设置邮箱
git config --global color.ui true                   启用默认的颜色
git config --list                                   查看配置列表
分支名称
master、develop、功能(feature)分支、预发布(release)分支、修补bug(fixbug)分支
生成秘钥
ssh-keygen -t rsa                                  生成ssh公私钥
~/.ssh/                                            秘钥位置
ssh git@192.168.1.239                              测试ssh秘钥是否设置成功
diff命令
git diff <file>                                    比较当前文件和暂存区文件差异
git diff
git diff <$id1> <$id2>                             比较两次提交之间的差异
git diff <branch1>..<branch2>                      在两个分支之间比较
git diff --staged                                  比较暂存区和版本库差异
git diff --cached                                  比较暂存区和版本库差异
git diff --stat                                    仅仅比较统计信息
show命令
git help <command>                                显示commandhelp
git show                                          显示某次提交的内容
git show $id
stash命令
git stash                                        暂存
git stash list                                   列所有stash
git stash apply                                  恢复暂存的内容
git stash drop                                   删除暂存区
git命令
git init                                           仓库初始化
git clone 地址                                      git下载源码

git status                                         查看状态
git pull origin <branchname>                       更新代码
git push origin <branchname>                       推送代码
git diff <filename>                                查看修改内容
git push origin --delete <branchname>              删除远程分支:
git push -f                                        强制推送远程回滚

git add <filename>                                 添加代码到暂存区
git commit -m  "注释"                              提交代码到版本库
git commit -a -m  '注释'                           添加并提交到版本库

git log <--pretty=oneline>                        查看历史记录
git reflog                                        查看历史记录(包含已回退的)

git checkout -- <fileName>                        还原工作区文件
git reset HEAD <fileName>                         还原文件暂存区到工作区
git reset --hard HEAD^ <HEAD~1>                   还原已提交未推送远程的文件
git reset --hard <版本号>                          还原文件到某个版本
git reset -–hard origin/master                    回退到和远程一样

git branch -m <oldname> <newname>                 修改本地分支名称
git branch -d <branchname>                        删除本地分支
git branch -D <branchname>                        强制删除分支

git branch <-a>                                   查看分支
git checkout <branchname>                         切换分支
git checkout -b <branchname>                      创建+切换分支
git log --graph --pretty=oneline --abbrev-commit  查看合并的分支图表

git merge <branchname> <--no-ff(生成节点)>        合并某分支到当前分支
git cherry-pick commitid                         合并某一次提交到当前分支

git tag <tagName> <commitId> -m "comment"        添加标签
git tag                                          标签列表
git show <tagName>                               标签详细查看

git push origin <tagName>                        提交单个标签到远程
git push origin --tags                           提交全部标签到远程

git tag -d <tagName>                             删除本地标签:
git push origin --delete tag <tagName>           删除远程标签

git stash                                        当前工作现场存储起来
git stash list                                  工作现场存储列表
git stash pop                                   恢复工作现场(删除储藏)
git stash apply                                 恢复工作现场(不删除储藏)
git stash drop                                  手动删除储藏

git cherry-pick commit11  commit2               同时提交多个
git cherry-pick commit11..commit2               左开右闭
git cherry-pick commit1^..commit2               左闭右闭
修改分支名称
1、重命名本地分支
git branch -m old_branch new_branch

2、推送重命名后的本地分支到远程仓库
git push origin new_branch

3、删除远程仓库上旧分支
git push origin --delete old_branch

4、如果出现删除远程仓库旧分支失败的情况
可能删除的分支属于默认分支

5、根据提示设置
git branch --unset-upstream

6、再次推送
git push --set-upstream origin new_branch
批量更新文件夹下载的项目及项目的各个分支更新
#/bin/bash
Opensource=`pwd`
cd ${Opensource}

currentpath=$(pwd)

echo "currentpath is >>>>>>>>> $currentpath"
echo ""

for i in `ls|grep -v rbc-pull|cat`
do
echo ""
cd $i
echo "current project is :$i"
echo ""

 for i in `git branch -a|grep remotes|grep -v HEAD|grep dev|awk -F "/" '{print$3}'|cat`
 do
 echo ""
 echo "$i"
 git checkout $i
 git pull
 echo ""
 done

cd ..
echo ""
done
批量下载项目列表到本地
#/bin/bash
Opensource=`pwd`
cd ${Opensource}

currentpath=$(pwd)

echo "currentpath is >>>>>>>>> $currentpath"
echo ""

for i in `cat aa.txt`
do
echo ""
echo "current project is :$i"

 git clone $i

echo ""
done
自动合并分支
#!/bin/sh
###################################
######该脚本用于简化git合并分支工作
######用法:新建文件 tys-merge 保存本脚本,并copy至%GIT_HOME%\usr\bin目录下。在git-bash中可使用 tys-merge 命令
######示例将branch1合并到master:tys-merge branch1 master 
###################################

echo "-----------------------------checkout & pull $1-----------------"
git checkout $1
git pull --all
echo ""

echo "----------------------------checkout & pull $2---------------------"
git checkout $2
git pull --all
echo ""

echo "----------------------------merge $1 into $2---------------------"
git merge --no-ff $1

echo "----------------------------推送: git push"
posted @   rbcd  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示