Git命令

  • 配置环境: git config
  • 初始化本地库: git init
  • 分支相关操作: git branch
  • 创建+切换分支:git checkout –b name
  • 切换分支: git checkout
  • 合并某分支到当前分支:git merge name
  • stage所有文件: git add .
  • commit stage的文件: git commit -m "comment of this commit"
  • 添加远程库到项目: git remote add aliasOfRemoteRepository https://serveraddress/nameofremote_repository.git
  • 提交代码到远程库: git push aliasOfRemoteRepository master
  • 更新本地代码: git pull aliasOfRemoteRepository master
  • 获取远程代码的一份拷贝: git clone https://serveraddress/nameofremote_repository.git
  • 创建别名: git config --global alias.c 'commit -m'
  • 查看提交日志: git log
  • 查看repository的状态: git status
  • 回退到上一个版本: git reset --hard HEAD^
  • 回退到上100个版本: git reset --hard HEAD~100
  • 回到具体的版本: git reset --hard versionNumber
  • 查看所有的版本号: git reflog
  • 撤销未Stage的修改: git checkout -- filename
  • 建立追踪关系,在现有分支与指定的远程分支之间: git branch --set-upstream [branch] [remote-branch]
原文地址:https://www.cnblogs.com/dereklovecc/p/5243110.html