git init//使用当前目录作为Git仓库,我们只需使它初始化。
git config --global user.name "Your Name"
git config --global user.email
"email@example.com"
git add *.c//添加文件,告诉Git开始对这些文件进行跟踪
git commit -m “beizhu” abc.txt//把文件提交到仓库(备注打双引号,文件名可不写)
git status//查看状态
git diff readme.txt//查看具体修改了什么内容
git last//最近一次提交
git log//历史记录(好好写备注)

git log --pretty=oneline//历史记录

git reset --hard d1bdd72c00e87a46e4c8f0753d426014a1226412//回到指定版本(版本号不用写全,前几个就好)
git reset --hard HEAD^^//回到上个版本(两个^未一个版本,HEAD~100前100版本)
git reflog//查看操作命令

git reset --hard 3cb5544//返回指定操作(git reflog返回的命令commit id)
git reset --hard HEAD@{1}

git chechout -- 1.txt//丢弃工作区(stage)修改,用版本库里的版本替换工作区的版本
git rm readme.txt//删除文件
远程:
注册GitHub账号
打开Git Bash(Git Bash,Git Bash。不是cmd!!!)输入
ssh-keygen –trsa –C “email@example.com”,在C:\Users\Administrator会生成.ssh文件
.ssh内有两个文件,复制id_rsa.pub文件内容,放在Key内

点击AddSSH Key
在GitHub创建一个Git仓库

git remote add origin git@github.com:littleStar123/learngit.git//关联
(origin为远程库名,littleStar123为git用户名)
git push -u origin master //提交
git clone git@github.com:littleStar123/gitskills.git//下载gitskills到本地
git remote rm origin //删除远程库
git remote//查看远程仓库
git remote –v

git push -u origin dev//提交分支

git checkout –b dev origin/dev
分支:
查看分支:git branch
创建分支:git branch dev
切换分支:git checkout dev
创建+切换分支:git checkout -b dev
合并某分支到当前分支:git merge dev
删除分支:git branch -d dev
强行删除分支:git branch -D dev(分支上有未提交的就会不能删需要强行删除)
当冲突时合并

修改后再提交
git log –graph //查案分支合并图。

Stash
git stash//保存当前到stash
git stash list//查看stash
git stash apply//恢复,但是恢复后,stash内容并不删除
git stash pop//恢复,但是恢复后,stash内容删除
git stash apply stash@{0}//恢复指定stash
git tag v1.0//打标签(当前分支)
git tag v1.0 3cb5544 //打标签(当前分支,打在commit上,3cb5544为commit id)
git tag//查看标签
git showv1.0//查看标签信息
git tag –d v1.0//删除标签
git push origin v1.0 //推送标签
git push origin --tags //推送所有未推送的标签
git push origin :refs/tags/v1.0//产出远程的tag(先删本地再提交)
忽略特殊文件
在Git工作区的根目录下创建一个特殊的.gitignore文件(.gitigiore文件,要放到版本库中)
https://github.com/github/gitignore (git配置)
git add –f App.class //-f强制添加
git check-ignore –v App.class//检查.gitignore
别名
git config --global alias.st status//st表示status(global 全局,不加global表示当前库)
删除别名,在.git/config文件中,删除对应行
全文参考廖雪峰老师的git教程https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
网友评论