git ----> 基本使用

git 基本命令之一

git init 初始化一个git仓库

git add file1 file2 ...  允许把一个或者多个文件添加到仓库

git commit -m "xxxx"  把文件提交到仓库

git status 查看工作区的状态

git diff 查看修改内容

git diff HEAD -- file1 查看工作区和版本库的区别(未提交和已提交)

git log 查看提交历史记录(--pretty=online参数可简化输出内容,内容只包括commit id和添加的内容)(穿梭时空用)

git log --graph --pretty=oneline --abbrev-commit 以图形化的形式查看分支合并情况

git log -1 查看最近一次提交的信息

git reset --hard HEAD^ 回退到上一个版本(丢弃提交到仓库的修改)

git reset --hard commit_id 回退到某一个提交历史点(丢弃提交到仓库的修改)

git reflog 查看命令历史(重返未来用)

git checkout -- file1 丢弃工作区的修改,恢复到未修改以前(最近的一次状态);可以把误删除的文件恢复到最新版本

git reset HEAD file1 结合下面的命令,该组合的功能:丢弃暂存区的修改,恢复到未修改以前(最近的一次状态)

git checkout -- file1

git rm file1 结合下面的命令,该组合的功能:删除版本库中的文件

git commit -m "xxxx"

git 基本命令之二

做好前期准备

git remote add origin github地址 关联一个远程仓库

git push -u origin master 关联后,第一次推送本地仓库master分支的所有内容到远程仓库

git push origin master 本地提交后,可推送最新修改到远程仓库

git clone 仓库地址 克隆远程仓库

git remote -v 查看远程仓库的详细信息

git push origin <branch_name> 从本地推送分支(建议先git pull)

git push origin <tag_name> 从本地推送标签

git push origin --tags 一次性推送全部未推送的标签到远程分支

git checkout -b <branch_name> origin/<branch_name> 在本地创建和远程分支对应的分支(本地和远程分支的名字最好一样)???

git branch --set-upstream <branch_name> origin/<branch_name> 建立本地分支和远程分支的关联???

git pull 抓取远程分支的新提交(建议:先pull,本地合并后再push)

git 基本命令之三

git branch 查看分支

git branch <branch_name> 创建分支

git branch -d <branch_name> 删除分支

git branch -D <branch_name> 强行删除分支

git checkout <branch_name> 切换分支

git checkout -b <branch_name> 创建+切换分支

git merge <branch_name> 合并某分支到当前分支

git merge --no-ff -m "xxxx" <branch_name> 合并分支,但是禁用 fast-forward模式

git stash 把当前工作现场“储藏”起来

git stash list 查看“隐藏的”工作现场

git stash pop 恢复工作现场,并且把stash内容删除

git stash apply stash@{0...} 恢复指定的stash

git stash apply 结合下面的命令,该组合的功能恢复工作现场,并且把stash内容删除

git stash drop

git cherry-pick commit_id 复制一个特定的提交到当前分支 ???

git rebase 把分叉的提交变成直线???

git 基本命令之四

git tag 查看所有标签

git tag <tag_name> 打标签

git tag <tag_name> <commit_id> 给指定的提交id打标签

git show <tag_name> 查看指定标签的信息

git tag -a <tag_name> -m <message> <commit_id> 创建带有说明的标签

git tag -d <tag_name> 删除标签

git tag -d <tag_name> 结合下面的命令,该组合的功能:删除一个远程标签

git push origin :refs/tags/<tag_name>

git 基本命令之五

git config ---global alias.<abbrev-name> <commad_part_name> 配置一个代替原来部分命令的单词的别名,例如:

git config --global alias.co checkout

参考资料:

https://git-scm.com/book/zh/v2

https://www.liaoxuefeng.com/wiki/896043488029600

猜你喜欢

转载自www.cnblogs.com/mrray1105/p/11360534.html