高效使用git的一些命令

  1,添加文件到版本库
        添加单个文件: git add filename
        添加所有txt文件: git add *.txt
        添加所有修改文件: git add .
  2,提交
        提交所有修改: git commit -m "commit msg" -a
        提交单个修改: git commit -m "commit msg" filename
        修改commit信息: git commit --amend
  3,撤销修改
        撤销尚未提交的修改: git checkout 1.txt 2.txt
        撤销提交: git revert head(反转提交,撤销最近一次的提交并且会产生一个新的commit信息)
        复位: git reset HEAD filename(取消暂停)
            git reset --hard HEAD^(撤销)
  4,分支
        列出本地分支: git branch
        列出所有分支: git branch -a
        基于当前分支创建新分支: git branch branchcname
        切换分支: git checkout branchname
        基于当前分支创建新的分支并且切换到新的分支: git checkout -b branchname
        基于某次提交,分支或者tag创建分支: git branch branchname bf357de
                                                                                          git branch branchname tagname
  5,合并
        普通合并: git merge branchname
        挑选合并: git cherry-pick bf357de
        压缩合并: git merge --squash branchname
        其它: git rebase branchname
        reabse: git rebase -i

  6,删除分支
        git branch -d branchname
        git branch -D branchname(强制删除分支)
  7,查看状态
        git log --oneline --graph
        gitk 查看当前分支历史
        gitk branchname 查看特定分支历史
        gitk -all 查看所有分支历史
        gitk filename 查看某文件的历史记录
  8,remote
        git clone
        git pull origin branchname
        git push origin branchname
        git push origin tagname
  9,config
        生成ssh密钥: ssh-keygen.exe -t rsa
        配置邮箱: git config --global user.email *****.com
        配置用户名: git config --global user.name your-id

原文地址:https://www.cnblogs.com/jones-c/p/3863560.html