GIT 常用命令
-
克隆指定分支:git clone -b feature/interface ssh://git@git.sankuai.com/sjst/mall-item.git
-
切换本地分支:git checkout -b bugfix/codereview
-
切换远程分支: git checkout -b dev origin/dev 作用是checkout远程的dev分支,在本地起名为dev分支,并切换到本地的dev分支
-
查看当前分支 git branch
-
覆盖本地分支
-
git fetch --all
-
git reset --hard origin/master
-
-
执行下面命令查看远程分支和本地分支的对应关系:git remote show origin
-
删除本地分支:$ git branch -d <BranchName>
-
查看项目的分支们(包括本地和远程) 命令行 : $ git branch -a
-
重命名git本地分支 : Git branch -m old_local_branch_name new_local_branch_name
-
创建本地分支:$ git branch <BranchName>
-
查看分支的创建时间:git reflog show --date=iso <branch name>
-
git add -u:将文件的修改、文件的删除,添加到暂存区。
git add .:将文件的修改,文件的新建,添加到暂存区。
git add -A:将文件的修改,文件的删除,文件的新建,添加到暂存区。
工作中一般是用到 git add . 或者 git add -A
git add -A相对于git add -u命令的优点 : 可以提交所有被删除、被替换、被修改和新增的文件到数据暂存区,而git add -u 只能操作跟踪过的文件
git add -A 等同于git add -all -
git log --all --n4 --oneline --graph 图形方式查看commit日志
-
git revert -n commit_id 撤销某些commit, 其后的commit保留,建议从最新->最旧commit来撤销,避免冲突https://www.jianshu.com/p/9299e32faa62
-
1、切换到master分支,执行打tag命令:git tag -a {tag名称} -m "tag说明";
2、push tag命令:git push --tags
统计代码行:
git log --format='%aN' | sort -u | while read name; do echo -en "name" --pretty=tformat: --numstat | awk '{ add +=
2; loc +=
2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
git log --author="your_name_here" --pretty=tformat: --numstat | awk '{ add += 2; loc +=
2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'
pull request 出现冲突时, 从master上合并代码,并提交,可以使用 git status 提醒
--- 出现git push被拒绝时,
git fetch
git pull origin bugfix/codereview
git push --set-upstream origin bugfix/codereview
---- 出现提交pl冲突时
git checkout master
git pull
git checkout bugfix/codereview
git merge master
git add .
git commit -m "从master合并代码"
git push