Git 全局信息配置
$ git config --lsit
$ git config --global user.name "bolonotlobo"
$ git config --global user.email "bytemaster2025@gmail.com"
初始化Git代码库
$ git init
$ git init git-demo
$ git clone [github仓库url]
暂存区 添加、删除、恢复
$ git add README.md
$ git add assets/
$ git add .
$ git add --all
$ git rm --cached README.md
$ git reset HEAD -- [文件名]
$ git reset HEAD -- [文件夹名]
$ git reset HEAD -- .
$ git mv [file-original] [file-renamed]
$ git checkout [文件名]
$ git checkout .
历史区(也叫本地仓库区) 提交、回退
$ git commit -m [message]
$ git commit [file1] [file2] ... -m [message]
$ git reset --hard [版本id]
$ git checkout [版本历史id] [要恢复的指定文件名]
$ git checkout 724a1992ab1bb9365b3e829e4307c6d07409a0ac index.html
Git 分支 新建、切换、删除
$ git branch
$ git branch dev
$ git checkout dev
$ git checkout -
$ git checkout -b feature-login
$ git branch -d [分支名]
$ git branch --delete [分支名]
$ git push origin -d [分支名]
$ git push origin --delete [分支名]
Git 分支合并
$ git merge [分支名]
Git 查看信息
$ git status
$ git log
$ git log --pretty=oneline
$ gitk
$ git show [版本id]
Git 远程
$ git remote add [remote-shortname] [url]
$ git remote add origin https://github.com/bolonotlobo/git-remote-demo.git
$ git push [remote-shortname] [branch]
$ git remote show origin
$ git remote set-url origin [url]
$ git remote rm origin
$ git remote add origin [url]
$ git remote -v
$ git fetch [remote]
git push [remote] --all
其他
$ git stash
$ git stash pop
补充远程连接github
- 本地git和github使用SSH来通信的,前提先配置 SSH密钥。