- git官网中文教程:https://git-scm.com/book/zh/v2
- 廖雪峰-git教程:https://www.liaoxuefeng.com/wiki/896043488029600
- 菜鸟教程:https://www.runoob.com/git/git-tutorial.html
① 克隆一个仓库:clone
git clone <仓库地址>
git clone http://xxx/yyy.git
cd yyy
git branch
默认克隆的master分支,如果克隆一个非master分支,加上-b <分支名> :
git clone -b <分支名> <仓库地址>
git clone -b dev http://xxx/yyy.git
cd yyy
git branch
② 建立新的分支:checkout -b
git checkout -b devx <分支名>
git checkout -b dev1 master
git checkout -b dev2 dev
切换分支:checkout
git checkout <分支名>
git checkout master
git checkout devx
③ 对仓库中的文件修改后,将文件添加到暂存区:add
git add <文件名>或<目录>
git add /yourdir/changedFile.txt
git add /changedDir/file1.txt
git add .
add 添加后,使用commit 将暂存区内容添加到本地仓库中:(加-m 对本次提交进行简要说明)
git commit -m "your change info"
git commit -m "fix bug"
④ 将本地的分支推送到远程:push
git push origin <分支名>
git push origin devx
⑤ 将分支与master合并:merge
git checkout master
git merge --no-ff devx
git push origin master
git checkout devx
⑥ 其他
git diff <file>
git rm <file>
git branch -d <dev>
如何打标签? tag
git log --pretty=oneline
git tag -a v1.0 d32a97d
git push origin v1.0
git clone -b v1.0 http://xxx/yyy.git
附: 廖雪峰的官方网站-使用SourceTree:图形化界面,操作git。简洁明了的介绍了git常用命令和图形化界面操作。
待整理。。。
如何撤销? reset
合并后如何退回?
Check out, review, and merge locally
Step 1. Fetch and check out the branch for this merge request
git fetch origin
git checkout -b devx origin/devx
Step 2. Review the changes locally
Step 3. Merge the branch and fix any conflicts that come up
git fetch origin
git checkout origin/master
git merge --no-ff devx
Step 4. Push the result of the merge to GitLab
git push origin master
Tip: You can also checkout merge requests locally by following these guidelines.
|