这里主要记录一下自己在windows系统下常用的git命令行
操作远程仓库
查看远程仓库
git remote -v
本地刷新远程分支
git fetch
先刷新分支
git checkout develop
再切换到远程分支develop就可以了
操作分支
查看分支
git branch
查看当前分支
git branch -r
在当前分支下创建develop分支
git branch develop
注意:这里创建的develop分支是本地分支
切换到当前分支
git checkout develop
提交当前分支到远程
git push --set-upstream origin develop
拉取远程分支到本地
git clone -b 分支名 仓库地址
分支的快速切换与创建
git checkout -b develop
合并分支
git checkout master
git merge develop
先切换回master主分支,再合并develop分支到主分支
删除本地分支
git branch -D develop
删除本地分支不会影响远程
新建独立分支
不与其他任何分支拥有相同的版本祖先(使用场景:对于同一个组件库拥有React和Vue两个版本的情况)
git checkout --orphan new_branch
注意:新建独立分支后不要去提交空分支,空分支是提交不上去的
这时我们把react分支的代码提交上去
git add .
git commit -m 'add a react branch and name is new_branch'
提交到远程环境
git push origin new_branch
撤销当前修改操作
代码未添加到git
git checkout .
保存代码前使用此命令,就像打草稿一样,写错了擦掉^_^
代码已添加但没提交
git reset .
如果已经git add添加到本地,但是还没有commit和push,可以通过reset撤销
其他
git 版本回退
git reset --hard 98254defb0
回退到指定版本,这里不加哈希值98254defb0就回退到最新,加了就回退到指定版本
git避免代码审查
git commit --no-verify -m "XXX"
根据用户和时间统计代码行数
git log --author="myname" --since=2023-01-01 --until=2023-02-01 --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 }'
发版
npm publish