【总结思考】git常用指令总结

这篇博客详细列举了Git的各种常用命令,包括初始化仓库、克隆、分支管理、提交、回滚、合并、标签及远程操作等。还提到了Git的图形化工具SourceTree作为界面化操作的推荐。此外,内容涵盖了Git的高级操作,如rebase、cherry-pick和reset等,是学习和日常使用Git的实用参考。
摘要由CSDN通过智能技术生成
  • $git --version git版本
  • $git init [project_name] 在当前目录新建一个Git代码库
  • $git clone [address] 拷贝代码到本地当前目录
  • $git config --global user.name “duffy” 配置用户名信息
  • $git config --global user.name 显示配置用户名
  • $git config --global user.email “duffy.wang@xxx.com” 配置email
  • $git config --global user.email 显示配置的email
  • $git config --global --list 显示当前Git配置
  • $git config --global color.ui/status/diff/branch/interactive 自动着色
  • $git branch 列出所有本地分支
  • $git branch -r 列出所有远程分支
  • $git branch -a 列出所有分支
  • $git branch -d feature_branch 删除分支 feature_branch
  • $git checkout -b [branch] 创建一个新的分支
  • $git checkout [branch] 从一个分支切换到其他分支,如git checkout master
  • $git checkout - 切换到上一个分支
  • $git status 显示有变更的文件
  • $git log 显示当前分支的版本历史
  • $git diff 显示暂存区与工作区的差异
  • $git diff [first_branch] [second_branch] 显示两次提交之间的差异
  • $git add . 添加当前目录所有文件到暂存区
  • $git add [file1] [file2] 添加指定文件到暂存区
  • $git add [dir] 添加指定目录到暂存区
  • $git commit -m “xxx” 提交暂存区到仓库区
  • $git commit [file1] [file2] -m “xxx” 提交暂存区的指定文件到仓库区
  • $git commit -v 提交时显示所有diff信息
  • $git push [remote] [branch] 上传本地指定分支到远程仓库,如git push origin main
  • $git pull [remote] [branch] 取回远程仓库变化,并与本地分支合并
  • $git checkout . 删除所有更改,但未暂挂的东西除外,目前没用过
  • $git clean -f 删除未跟踪文件的所有更改,目前没有改
  • $git checkout [branch] -> $git merge master 将不同分支与主分支合并
  • $git merge [branch] 合并指定分支到当前分支,如git merge
  • $git cherry-pick [commit] 选择一个commit,合并到当前分支,没使用过
  • $git revert [commit]新建一个commit用来撤销指定commit,后者的所有变化都将被前者抵消,相当于反向操作
  • $git reset -hard [commit] 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致,回滚最彻底
  • $git reset [commit] 重置当前分支的HEAD为指定commit,重置暂存区,工作区保持不变
  • $git reset -keep [commit] 重置当前分支的HEAD为指定commit,暂存区和工作区保持不变,回滚最不彻底
  • $git stash 暂时将未提交的变化移除,推荐使用git stash save “xxxx” 用于记录此次stash
  • $git stash pop 重新应用缓存stash,默认使用最近的stash,推荐使用 git stash apply “xxx“ 通过名字指定使用哪个stash,
  • $git stash list 查看现有stash
  • $git stash drop 移除
  • $git tag 列出所有tag
  • $git tag [tag] 新建一个tag在当前commit. git tag v0.1.0 -> git push origin v0.1.0
  • $git tag -am “xxx” tag注解和tag名.
  • $git rebase -i HEAD~ 修改最近的commit,汇合前count个commit 提交
  • $git submodule
# Rebase 326fc9f..0d4a808 onto d286baa
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message 修改注解
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit 
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

阮一峰大佬总结:
http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html

界面化操作推荐应用SourceTree,不用写git 指令

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值