git命令

一、git配置

在git中有三级配置,按级别高低从高到低分别是system(系统级)、global(全局级)、local(仓库级),对于同名配置项,低级别配置会覆盖高级别配置

  1. 配置用户名及邮箱
    git config --global/local user.name mike
    git config --global/local user.email mike@qq.com
  2. 配置命令缩写
    git config --global alias.co checkout
    git config --global alias.br branch
    git config --global alias.status st
    git config --global alias.l "log --oneline --graph"
    git config --global alias.ls 'log --graph --pretty=format:"%h <%an> %ar %s"'

二、git操作

  1. 初始化仓库:git init
  2. 将文件加暂存区:git add <文件>git add --allgit add .
  1. 无论要提交的文件是否在本地仓库中,都需要先add再commit。对于已提交至本地仓库的文件,可在commit时使用-a参数以省略add操作。
  2. 空目录无法被add
  1. git commit -a -m '-a参数提交'
  2. 查看日志:git log
  3. 查看特定文件的commit记录:git log -p <文件>
  4. 删除文件:git rm <文件>
  5. 去除git对文件的控制:git rm --cached <文件>
  6. 修改文件名:git mv test.txt test1.txt
  7. 查看git状态:git status
  8. 查看某些行代码是谁提交的:git blame -L 1,2 test.txt
  9. 从本地仓库检出某文件:git checkout <文件>git checkout HEAD~1 <文件>
  10. 回退版本:git reset master^git reset master~1
    请添加图片描述
    请添加图片描述
  11. 查看分支:git branch
  12. 新建分支:git branch <分支名>
  13. 修改分支名:git branch -m old_name new_name
  14. 删除分支:git branch -d <分支名>
  15. 切换分支:git checkout <分支名>
  16. 分支合并(方式1):git merge <分支名>
  17. 分支合并(方式2):git rebase <分支名>
  18. 增加名为practice_repo的远程仓库节点:git remote add practice_repo <仓库地址>
  19. 向远程节点推送master分支:git push -u practice_repo master,下次使用git push即可

-u参数用于设置默认推送的上游仓库分支,否则每次推送都要指明远程仓库

  1. 拉取远程仓库的更新:git pull

相关推荐

  1. git 命令

    2024-03-11 10:50:03       28 阅读
  2. Git 命令

    2024-03-11 10:50:03       26 阅读
  3. git 命令

    2024-03-11 10:50:03       37 阅读
  4. <span style='color:red;'>git</span><span style='color:red;'>命令</span>

    git命令

    2024-03-11 10:50:03      32 阅读
  5. <span style='color:red;'>git</span><span style='color:red;'>命令</span>

    git命令

    2024-03-11 10:50:03      26 阅读
  6. <span style='color:red;'>git</span><span style='color:red;'>命令</span>

    git命令

    2024-03-11 10:50:03      22 阅读
  7. <span style='color:red;'>git</span><span style='color:red;'>命令</span>

    git命令

    2024-03-11 10:50:03      7 阅读
  8. git命令

    2024-03-11 10:50:03       8 阅读
  9. <span style='color:red;'>git</span><span style='color:red;'>命令</span>

    git命令

    2024-03-11 10:50:03      8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-11 10:50:03       14 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-11 10:50:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-11 10:50:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-11 10:50:03       18 阅读

热门阅读

  1. 学习Android的第二十四天

    2024-03-11 10:50:03       20 阅读
  2. 我的创作纪念日

    2024-03-11 10:50:03       19 阅读
  3. MetaGPT部分源码解读

    2024-03-11 10:50:03       23 阅读
  4. wpf ListView 列表绑定demo

    2024-03-11 10:50:03       20 阅读
  5. 低代码测试自动化

    2024-03-11 10:50:03       23 阅读
  6. 【力扣】2562. 找出数组的串联值

    2024-03-11 10:50:03       57 阅读