clone(克隆代码)
git clone 远程仓库克隆地址
git clone -b 远程分支名 远程仓库克隆地址
add(暂存代码)
git add ./
commit(提交代码)
git commit -m '描述信息'
git commit -am '描述信息'
pull(拉取最新代码)
git pull origin 远程分支
push(推送代码)
git push origin master(本地分支):master(远程分支)
git push origin master --force
remote(关联远程仓库)
git remote add origin(名字随便取) 远程仓库克隆地址
branch(查看或创建分支)
git branch
git branch 新分支名
checkout(切换分支)
git checkout 分支名
git checkout -b 分支名
stash(暂时存储)
git stash
git stash apply
git stash save '描述信息'
git stash list
git stash apply stash@{1}
reflog(查看日志)
git log
git reflog
reset(版本回退)
git reset --hard HEAD^
git reset --hard 版本号
合并多次提交
参考: 使用git rebase合并多次commit
- 将本次提交合并到上一次提交
- git commit --amend
- 保存: wq 或 x
- 强制推送(注意: 本地分支可能会改变)
- 合并多次提交
git rebase -i startpoint endpoint
除了第一次提交,其他提交前面的pick都改为s
保存: wq 或 x
删除其他提交信息: dd删除行
保存: wq 或 x
强制推送(注意: 本地分支可能会改变)
代码提交量统计
git log --since ==2020-06-1 --until=2020-06-6 --author="$(git config --get user.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 }'