Common commands
# #在linux上安装git
sudo apt-get install git
# install Git on #在Mac OS x
Brew Install Git
# #配置全局name和email
git config--global user.name "your name"
git config--global user.email "[Email protected]"
# #初始化Git仓库
Git init
# #把文件添加到仓库
git add filename
# #把文件提交到仓库
Git commit-m "Worte a Memo"
# #查看仓库状态
git status
# #查看文件具体修改的内容
git diff <filename>
# #查看最近到最远的提交日志
git log
# #查看提交日志, simplifying information
git log--pretty=oneline
# #退回版本
##########################
#上一个版本是HEAD ^, on the page
#本是HEAD ^^, up to 100 versions
#是HEAD ~100.
##########################
git reset--hard HEAD ^
# #通过版本号退回
git reset--hard <commit id>
# #查看每一次命令执行日志
Git reflog
# #查询工作区文件与版本库里最新版本区别:
git diff HEAD--<filename>
# #丢弃工作区修改
Git checkout--<filename>
# #撤销暂存区修改
git reset HEAD <filename>
# #删除文件后把改变放到暂存区
git rm <filename>
# #gen key for Shh key
Ssh-t rsa-c "[Email protected]"
# #本地库与远程库关联
# #origin代表远程库名称, this is the default for Git, or it can be changed
Git remote origin [email protected]:p Ath/repositoryname.git
# #推送内容到远程库
# #第一次执行时加上-u parameter, which represents associating the local master branch with the remote master branch
Git push-u Origin Master
Git push Origin Master
# #克隆远程仓库到本地
git clone [email protected]:p Ath/repository.git
# #创建并切换分支
Git checkout-b <branchname>
# #创建和切换分支分步进行
Git branch Dev
git checkout Dev
# #查看当前的分支情况
Git branch
# #把其他分支工作成果合并到master分支上
git merge <branchname>
# #删除分支
Git branch-d <branchname>
# #查看git The branch merge of log:
git log--graph--pretty=oneline--abbrev-commit
# #禁用fast Forward Merge
Git merge No-ff-m "your Commit Memo"
# #把当前工作线程储藏起来
Git stash
# #查看stash情况
git stash List
# #恢复stash并删除
Git stash pop
# #恢复stash和删除stash也可分两步完成
Git stash Apply
git stash Drop
# #查看远程仓库信息
Git remote-v
# #推送分支
Git push Origin <branchname>
# #本地分支与远程分支关联
Git branch--set-upstream <branch-name> origin/<branch-name>
Common git commands