git常用操作手册

180 阅读1分钟

主流程操作

1.首次克隆远端仓库

git clone [协议]://github.com//[组织名]/[仓库名]
git clone https://github.com/bcl-chain/web3.go.git

/**  
* [xxx] means 必写可替换内容
* ([xxx]) means 可省可替换内容
*/

2.拉取最新项目

git pull [仓库名] ([分支名])
git pull origin local

/** 
* 也可以用
* git fetch [仓库名] ([分支名])
* git fetch origin local
*
* 区别
* git pull = git fetch + git merge
*/

2.查看本地仓库的状态

git status

/**
* 通过git status得知
* 1 仓库所在的上游分支(即仓库是从哪一个分支上克隆下来的)。
* 2.本地仓库相较于上游分支的仓库被改动和增加的文件。此时可以使用git diff [文件名] 查看被修改的文件。
* 3.通过提示完成剩下的操作
*/

3.提交修改

git add .

4.提交分支描述

git commit -m "branch description"

/**
*-m后加所提交分支的描述,提交分支后可以使用git log查看提交的日志。
*/

5.将本地仓库推到远端

git checkout -b [分支名]
/**
* 本地创建新分支
*/

git branch
/**
* 查看上游分支名
*/

git push origin [某上游分支名]:[个人分支名]
git push origin dev-200305-test:vivian-200612-test
/**
* 向仓库提交自己的分支
* 若默认修改后的版本直接推上主分支,直接git push
*/

6.PR

在网站上提交pull request并邀请同组成员review代码。

其它操作

1.修改文件夹名

git mv oldName newName 
git commit -m "XXX" 
git push 
git push -f origin master

2.回退到某当前分支的某版本

git log //查看所有分支的版本号
git reset 
    --hard [版本号] //慎用
    --soft

3.本地创建新仓库推送到远端

mkdir [NewRepoName]
cd [NewRepoName]
git init
touch README.md
vi README.md
git add README.md
git commit -m "XXX"
git remote add origin https://github.com/misakisaysyes/LeetCodeNote.git
git push -u origin master