git命令

git常用命令:git clone、git push、git add、git commit、git checkout、git pull
在这里插入图片描述
解释:

  • workspace:工作区
  • staging area:缓存区
  • local repository:本地仓库
  • remote repository:远程仓库
命令说明
git init初始化本地仓库
git clone从remote下载文件到local
git add添加文件到staging area
git commit将staging area中的内容提交到local repository
git diff比较staging area和workspace内容的差异
git status查看当前仓库的状态,显示有变更的文件
git reset回退版本
git rm删除workspace文件
git mv移动或重命名workspace文件
git log查看历史提交记录
git blame 以列表的形式查看指定文件的历史修改记录
git remote远程仓库操作
git fetch从远程仓库获取代码
git pull下载远程代码并合并
git push上传远程代码并合并

首次上传代码

  1. 在gitlab上创建项目
  2. 在git bash上配置用户名和邮箱
git config --global user.email ccc@example.com
git config --global user.name ccc
git config --global http.sslVerify false
  1. git add .
  2. git commit -m 提交注释
  3. git pull origin master --allow-unrelated-histories
  4. git push -u origin master

分支

使用checkout切换分支时,查找顺序:本地分支 --> 远程分支 --> 提示分支不存在

# 查看本地分支
git branch
# 查看远程分支
git branch -r
# 查看所有分支
git branch -a
# 推送本地分支
git push origin test(分支名)
创建并切换分支
# 创建本地分支
git branch my_branch
# 切换本地分支
git checkout my_branch
# 创建并切换本地分支
git checkout -b my_branch
# 重置分支(删除已存在的分支并重新创建,分支不存在也不报错)
git checkout -B my_branch
#本地分支重命名
git branch -m 旧分支命 新分支名
# 当前分支重命名
git branch -m 新分支名

删除分支
# 删除本地分支
git branch -d my_branch
# 删除本地分支(远程分支不存在的情况)
git branch -D my_branch
# 删除远程分支
git push origin --delete my_branch
撤销更改:让工作区的文件回到最近一次git add或git commit的状态。
git checkout -- .  (撤销所有文件更改)
git checkout -- file1 file2 (撤销工作区的某些文件更改)
撤销缓存区的更改
gie reset my_branch -- file1 file2

统计代码总量

find . -name "*.txt" -or -name "*.h" -or -name "*.py" -or -name "*.robot" |xargs grep -v "^$"|wc -l

查看个人代码量

git log --author="zhangsan" --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 log --format='%aN'|sort -u | while read name; 
 do echo -en "$name\t"; 
 git log --author="$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}' -; 
 done

统计提交数

git log --oneline | wc -l
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值