GIT 常用命令

2021-04-01  本文已影响0人  小木盒子
  1. 克隆指定分支:git clone -b feature/interface ssh://git@git.sankuai.com/sjst/mall-item.git

  2. 切换本地分支:git checkout -b bugfix/codereview

  3. 切换远程分支: git checkout -b dev origin/dev 作用是checkout远程的dev分支,在本地起名为dev分支,并切换到本地的dev分支

  4. 查看当前分支 git branch

  5. 覆盖本地分支

    1. git fetch --all

    2. git reset --hard origin/master

  6. 执行下面命令查看远程分支和本地分支的对应关系:git remote show origin

  7. 删除本地分支:$ git branch -d <BranchName>

  8. 查看项目的分支们(包括本地和远程) 命令行 : $ git branch -a

  9. 重命名git本地分支 : Git branch -m old_local_branch_name new_local_branch_name

  10. 创建本地分支:$ git branch <BranchName>

  11. 查看分支的创建时间:git reflog show --date=iso <branch name>

  12. 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

  13. git log --all --n4 --oneline --graph 图形方式查看commit日志

  14. git revert -n commit_id 撤销某些commit, 其后的commit保留,建议从最新->最旧commit来撤销,避免冲突https://www.jianshu.com/p/9299e32faa62

  15. 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\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 --author="your_name_here" --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 }'

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

上一篇 下一篇

猜你喜欢

热点阅读