git常用命令

1. 初始设置

  • git config --global user.name "Your Name" 设置用户名
  • git config --global user.email "email@example.com" 设置Email
  • git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" 设置 git lg 命令为查看历史消息
  • git config --global credential.helper store 记住Http 连接密码
  • git config --system --unset credential.helper store 清除已经记住的http连接密码
  • git config --global core.quotepath false 正确显示 中文字符串
  • ssh-keygen -t rsa -C "youremail@example.com" 设置产生私钥和公钥

2. 本地命令

  • git init : 创建版本管理库
  • git log : 查看历史信息,也可以使用如上设置的 git lg
  • git clone xxxx: 克隆远程仓库
  • git tag V0.1 打标签
  • git tag -d V0.1 删除标签
  • git push origin --tags 推送标签到远程
  • git status : 查看当前库的状态
  • git add specific_file 添加具体文件的操作到缓存区,注意, git add .命令中使用了通配符.,可以添加本次仓库变更的所有内容到缓存区,在使用此命令前,一定要用 git status 查看当前仓库状态。
  • git rebase -i specific_commit_hash (-i 为"interactive", 需要用户互动选择commit,详情可百度),将所指定的commit以及所有此commit以后的commits压缩为一个commit,为让 git log 历史清晰干净
  • git clone -b xx_tag --depth=1 url 检出某个 tag 的代码,不包含其它的内容,针对大仓库会加快速度

3. 远程命令

  • git pull origin dev 拉去 dev 分支内容
  • git push origin --all 推送所有分支内容到远程
  • git push origin dev 推动 dev 分支到远程
  • git push -u origin master -f 强制push,会使远程修改丢失,在多人开发时不建议这么操作。

4. 分支相关

  • 查看分支:git branch -a
  • 创建分支:git branch <name>
  • 切换分支:git checkout <name>
  • 创建+切换分支:git checkout -b <name>
  • 合并某分支到当前分支:git merge <name>
  • 删除分支:git branch -d <name>
  • 本地分支与远程分支关联 :git branch -u origin/dev
  • 切换分支并与远程分支关联 :git checkout -b local origin/dev
  • 创建空分支: git checkout --orphan doc

5. Merge

  • git config --global mergetool.meld.path "/c/Program Files (x86)/meld/meld.exe" 设定merge工具 (可选,不设置就使用默认工具)
  • git merge dev 在当前分支,同步/合并 dev 分支的内容,并存在当前分支
  • git checkout --theirs file.xml 解决冲突,使用远程文件
  • git checkout --ours file.xml 解决冲突,使用本地文件

6. 子模块

  • git submodule init 子模块仓库初始化
  • git submodule update --remote 子模块仓库当前分支更新
  • git submodule add -f '+git_path+' '+file_path 添加子仓库
  • git submodule deinit -f ' + file_path 删除子模块
  • git rm -f ' + file_path 删除子模块

7. 仓库迁移

  • 使用裸仓库指令clone下原仓库 git clone --bare xxx_a
  • 在仓库中添加另外远程地址 git remote add remote2 xxx_b
  • 推送仓库到另外远程地址 git push --mirror remote2

半山腰总是挤的,你得去山顶看看。 熬过无人问津的日子,才有诗和远方。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

又菜又爱好Bug东

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值