git basic commands

basic commands

1.全局设置用户名
$ git config --global user.name "YourName"               
2.全局设置邮箱    
$ git config --global user.email "[email protected]"     
3.初始化仓库  
$ git init                                         
4.把文件添加到仓库
$ git add
5.添加所有文件到仓库
$ git add .
6.把所有文件提交到仓库
$ git commit -m "comment message"
7.推送分支
$ git push origin tagname
8.查看状态
$ git status
9.查看文件修改的内容
$ git diff filename
10.拉取更新
$ git pull
11.撤消指定的提交
$ git revert<commit>
12.查看远程仓库
$ git remote -v
13.查看远程服务器地址和仓库名称
$ git remote -v;
14. View updated content
$ git diff
15. View the current directory
$pwd
16. Create folders
$ mkdir name

version control

1.查看历史记录
$ git log
$ git reflog
2.回退版本
$ git reset --hard HEAD^
$ git reset --hard 3628164
3.丢弃工作区修改
$ git checkout -- filename
4.从版本库删除文件
$ git rm test.txt

Remote warehouse control

1.关联远程苍库
$ git remote add origin git@server-name:path/repo-name.git
2.关联后第一次推送
$ git push -u origin master
3.克隆一个本地库
$ git clone git@server-name:path/repo-name.git

branch management

1.查看分支
$ git branch
2.查看所有分支(包括远程分支)
$ git branch -a
3.切换分支
$ git checout branchname
4.创建分支
$ git branch name
5.创建+切换分支
$ git checkout -b name
6.合并到某分支
$ git merge name
7.删除分支
$ git branch -d name
8.删除远程分支
$ git push origin :delbranchname #origin后面一定要空一格
9.查看远程分支
$ git branch -r
10. Fetch all remote branches
$ git fetch
11. Merge branches without committing
$ git merge  –no-commit <some branch>

TAG

1.添加标签
$ git tag name
2.查看标签
$ git tag
3.推送标签
$ git push origin tagname
4.删除本地标签
$ git tag -d tagname

Skill

1.当手头工作没有完成时,先把工作现场git stash一下,然后去修复bug,修复后,再git stash pop,回到工作现场.
$ git stash
$ git stash pop

multi-person collaborative work

多人协作的工作模式,一旦熟悉了,就非常简单。
查看远程库信息,使用git remote -v;
本地新建的分支如果不推送到远程,对其他人就是不可见的;
从本地推送分支,使用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 pull,如果有冲突,要先处理冲突。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326257319&siteId=291194637