Git 分布式版本控制系统
- 初始化Git仓库:
git init - 添加文件到Git仓库:
first-step: git add <file>second-step: git commit -m <message> - 工作区状态:
git status - 查看修改内容:
git diff - 回退上一次版本:
git reset --hard HEAD^ - 回退指定次数版本:
git reset --hard HEAD~100 - 回退到指定版本:
git reset --hard commit_id - 查看提交历史:
git logORgit log --pretty=oneline - 查看命令历史:
git reflog - 查看工作区和版本库最新版本区别:
git diff HEAD -- <file> - 丢弃工作区修改内容:
git checkout -- file - 丢弃暂存区内容:
git reset HEAD <file> - 删除版本库中文件:
git rm file
- 关联远程库:
git remote add origin git@server-name:path/repo-name.git - 第一次推送master分支所有内容:
git push -u origin master - 推送最新master分支修改:
git push origin master - 从远程库克隆一个仓库:
git clone git@server-name:path/repo-name.git - 查看远程库信息:
git remote -v - 删除指定远程连接:
git remote rm <connection-name> - 本地新建的分支如果不推送到远程,对其他人是不可见的
- 从本地推送分支:
git push origin <branch-name> - 抓取远程新提交内容:
git pull - 在本地创建和远程分支对应的分支:
git checkout -b <branch-name> origin/<branch-name> - 建立本地分支和远程分支的关联:
git branch --set-upstream <branch-name> origin/<branch-name>
- 查看分支:
git branch - 创建分支:
git branch <branch-name> - 切换分支:
git checkout <branch-name> - 创建&切换分支:
git checkout -b <branch-name> - 合并指定分支到当前分支:
git merge <branch-name> - 普通模式合并(合并后的历史有分支显示)指定分支到当前分支:
git merge --no-ff -m <message> <branch-name> - 删除分支:
git branch -d <branch-name> - 强行删除没有被合并过的分支:
git branch -D <branch-name> - 查看分支合并图:
git log --graph --pretty=oneline --abbrev-commit
- "隐藏"工作现场:
git stash - 查看被隐藏的所有工作现场:
git stash list - 恢复工作现场:
git stash pop
- 新建一个标签:
git tag <tagname>ORgit tag <tagname> <commit-id> - 新建一个标签并指定标签信息:
git tag -a <tagname> -m <message> <commit-id> - 查看所有标签:
git tag - 查看标签信息:
git show <tagname> - 删除一个本地标签:
git tag -d <tagname> - 删除一个远程标签:
git push origin :refs/tags/<tagname> - 推送一个本地标签:
git push origin <tagname> - 推送全部未推送的本地标签:
git push origin --tags
- 修改配置:
git config --global alias.co checkout
Git 暂存区:
git add <file>
git commit -m <message>
参考文源:Git教程

git add <file>
git commit -m <message>









网友评论