Files
Linux/Git/GIt的使用.md
offends cee91802b3
Some checks failed
continuous-integration/drone Build is failing
synchronization
2025-08-25 15:57:40 +08:00

1.4 KiB

本文作者:丁辉

GIt的使用

官网

基础命令

  • 新建分支

    git branch demo
    
  • 切换分支

    git checkout demo
    
  • 新建并切换到新分支

    git checkout -b demo
    
  • 合并分支

    git merge hotfix
    
  • 删除分支

    git branch -d hotfix
    
  • 查看状态

    git status
    
  • 启动一个合适的可视化合并工具

    git mergetool
    
  • 添加仓库

    git remote add origins Git地址
    
  • 拉取代码

    git pull origins
    
  • 查看提交信息

    git log
    
  • 回滚代码

    git reset --hard ID信息
    
  • 不回滚已修改的代码

    git reset ID信息
    
  • 清楚缓存

    git credential-cache exit
    

跨分支合并某个提交记录

例子:假如我有 A 、B 分支

  1. 切换到 A 分支

    git checkout <A分支>
    
  2. 查看提交日志拿到值

    git log
    
  3. 切换到 B 分支

    git checkout <B分支>
    
  4. 合并

    git cherry-pick '获取到的提交记录值'
    
  5. 检查提交记录,查看是否将 A 文件合并到了 B 仓库

    git log
    
  6. 提交文件

    git add .
    git push