git - wtdig/study GitHub Wiki

git指令

指令参考:http://note.youdao.com/noteshare?id=3c6611caeb89d06e8c4beab99ab92426

1、创建本地git仓库

mkdir xxxx

cd xxx

pwd 查下当前的目录

git init 初始化本地仓库

2、添加新文件

git add 文件的全称 含义:将文件添加到暂存区

git commit -m '注释' 含义:将暂存区所有的文件提交到仓库中

3、查看状态

git status

4、查看修改内容,不同点

git diff

5、查看提交的日志

git log --pretty=oneline

6、版本的回退

git reset --hard HEAD^ 将本次的版本回退到上一次版本

7、查看文件的具体内容

cat 文件全称

8、回退到指定版本

git reset --hard 版本序列号(可以不全)

9、记录每一次输入的指令

git reflog

10、撤销修改

git checkout -- readme.txt

git checkout其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。

命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:

一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;

一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。

总之,就是让这个文件回到最近一次git commit或git add时的状态。

11、删除文件

rm 文件的全称

删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交

12、关联本地仓库和远程仓库

git remote add origin [email protected]:自己的github账户名/仓库名.git

例如:git remote add origin [email protected]:michaelliao/learngit.git

13、把本地库推送到远程仓库

git push -u origin master

把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。

由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。

推送成功后,可以立刻在GitHub页面中看到远程库的内容已经和本地一模一样

从现在起,只要本地作了提交,就可以通过命令:

$ git push origin master

把本地master分支的最新修改推送至GitHub,现在,你就拥有了真正的分布式版本库

14、从远程克隆一个本地库

git clone [email protected]:github账户名/仓库名.git

例如:git clone [email protected]:michaelliao/gitskills.git

15、创建分支切换到分支

git checkout -b dev

git checkout命令加上-b参数表示创建并切换,相当于以下两条命令:

$ git branch dev

$ git checkout dev

16、查看当前分支

git branch

git branch命令会列出所有分支,当前分支前面会标一个*号

17、切换分支

git checkout master

18、合并分支

git merge dev

我们把dev分支的工作成果合并到master分支上

19、删除指定的分支

git branch -d dev

查看分支:git branch

创建分支:git branch name

切换分支:git checkout name

创建+切换分支:git checkout -b name

合并某分支到当前分支:git merge name

删除分支:git branch -d name

20、分支策略

git merge --no-ff -m "merge with no-ff" dev

合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支, 能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并.

在实际开发中,我们应该按照几个基本原则进行分支管理:

首先,master分支应该是非常稳定的,也就是仅用来发布新版本,平时不能在上面干活;

那在哪干活呢?干活都在dev分支上,也就是说,dev分支是不稳定的,到某个时候,比如1.0版本发布时,再把dev分支合并到master上,在master分支发布1.0版本;

你和你的小伙伴们每个人都在dev分支上干活,每个人都有自己的分支,时不时地往dev分支上合并就可以了。

21、查看远程仓库信息

git remote

git remote -v显示更详细的信息

22、推送分支

推送分支,就是把该分支上的所有本地提交推送到远程库。推送时,要指定本地分支,这样,Git就会把该分支推送到远程库对应的远程分支上:

$ git push origin master

如果要推送其他分支,比如dev,就改成:

$ git push origin dev

但是,并不是一定要把本地分支往远程推送,那么,哪些分支需要推送,哪些不需要呢?

master分支是主分支,因此要时刻与远程同步;

dev分支是开发分支,团队所有成员都需要在上面工作,所以也需要与远程同步;

bug分支只用于在本地修复bug,就没必要推到远程了,除非老板要看看你每周到底修复了几个bug;

feature分支是否推到远程,取决于你是否和你的小伙伴合作在上面开发。

总之,就是在Git中,分支完全可以在本地自己藏着玩,是否推送,视你的心情而定

23、多人协作工作

因此,多人协作的工作模式通常是这样:

首先,可以试图用git push origin branch-name推送自己的修改;

如果推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并;

如果合并有冲突,则解决冲突,并在本地提交;

没有冲突或者解决掉冲突后,再用git push origin branch-name推送就能成功!

如果git pull提示“no tracking information”,则说明本地分支和远程分支的链接关系没有创建,用命令git branch --set-upstream branch-name origin/branch-name。

这就是多人协作的工作模式,一旦熟悉了,就非常简单

查看远程库信息,使用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,如果有冲突,要先处理冲突。

24、自定义git

git config --global color.ui true Git显示颜色,会让命令输出看起来更醒目:

案例: wb-wt261136@MININT-AOUKK2A MINGW64 ~ $ cd D:/sacpage

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage $ git clone http://gitlab.alibaba-inc.com/platform/fis_sac.git Cloning into 'fis_sac'... remote: Counting objects: 1346, done. remote: Total 1346 (delta 0), reused 0 (delta 0) Receiving objects: 100% (1346/1346), 23.44 MiB | 8.20 MiB/s, done.

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage $ git checkout -b daily/1.0.6 fatal: Not a git repository (or any of the parent directories): .git

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage $ cd fis_sac/

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (master) $ git checkout -b daily/1.0.6 Switched to a new branch 'daily/1.0.6'

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ npm install [email protected] D:\sacpage\fis_sac +-- [email protected] +-- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] -- [email protected] +-- UNMET PEER DEPENDENCY react@>=0.13.0 +-- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | | +-- [email protected] | | | +-- [email protected] | | | | -- [email protected] | | | +-- [email protected] | | | +-- [email protected] | | | +-- [email protected] | | | -- [email protected] | | -- [email protected] | | +-- [email protected] | | | +-- [email protected] | | | +-- [email protected] | | | +-- [email protected] | | | | -- [email protected] | | | +-- [email protected] | | | -- [email protected] | | +-- [email protected] | | +-- [email protected] | | -- [email protected] | | -- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | | -- [email protected] | | -- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | +-- [email protected] | | -- [email protected] | | -- [email protected] | | -- [email protected] | +-- [email protected] | +-- [email protected] | | -- [email protected] | | +-- [email protected] | | | +-- [email protected] | | | -- [email protected] | | -- [email protected] | +-- [email protected] | -- [email protected] | +-- [email protected] | | -- [email protected] | -- [email protected] | -- [email protected] | +-- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | +-- UNMET PEER DEPENDENCY react@^0.14.0 || ^15.0.1 | +-- UNMET PEER DEPENDENCY react-dom@^0.14.0 || ^15.0.1 | -- [email protected] | +-- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | +-- [email protected] | | +-- [email protected] | | -- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | +-- [email protected] | +-- [email protected] | +-- [email protected] | | +-- [email protected] | | -- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | | +-- [email protected] | | -- [email protected] | | -- [email protected] | +-- [email protected] | | +-- [email protected] | | +-- [email protected] | | +-- [email protected] | | | -- [email protected] | | -- [email protected] | +-- [email protected] | | +-- [email protected] | | -- [email protected] | | -- [email protected] | +-- [email protected] | | +-- [email protected] | | +-- [email protected] | | +-- [email protected] | | | -- [email protected] | | -- [email protected] | | -- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | +-- UNMET PEER DEPENDENCY react@>=0.13.0 | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | +-- [email protected] | +-- UNMET PEER DEPENDENCY react@>=0.13.0 | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | | -- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | +-- UNMET PEER DEPENDENCY react@^0.14.3 || ^15.0.0 | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | +-- [email protected] | | -- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] | +-- [email protected] | -- [email protected] +-- [email protected] | +-- [email protected] | -- [email protected] -- [email protected] -- [email protected]

npm WARN [email protected] requires a peer of react@>=0.13.0 but none was installed. npm WARN [email protected] requires a peer of react@>=0.13.0 but none was installed. npm WARN [email protected] requires a peer of react@>=0.13.0 but none was installed. npm WARN [email protected] requires a peer of react@>=0.13.0 but none was installed. npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.1 but none was installed. npm WARN [email protected] requires a peer of react-dom@^0.14.0 || ^15.0.1 but none was installed. npm WARN [email protected] requires a peer of react@^0.14.3 || ^15.0.0 but none was installed.

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ nowa lib

Update available: [email protected] (Current: 1.1.0) Run npm i nowa -g to update. Installing dependencies of libraries... [tnpm ?????o§??¤o] ??°?????o 4.19.4?????°?????o 4.19.1??èˉ·?°??????o§?°??°???? ????ˉ??¥?§è? tnpm install -g tnpm@release-4 ?¥??è£?-¤??? ?|???¤o?2???é??èˉ·?°èˉ sudo tnpm install -g tnpm@release-4

[1/12] uxcore-validator@~0.2.0 installed at node_modules.0.2.0@uxcore-validator [2/12] uxcore-formatter@~0.1.4 installed at node_modules.0.1.4@uxcore-formatter [3/12] uxcore-button@~0.4.6 installed at node_modules.0.4.10@uxcore-button anti semver [email protected] ao rc-select ao [email protected] use uxcore-select2's dependencies version: "^2.1.2" instead of "2.x" anti semver [email protected] ao rc-menu ao [email protected] use uxcore-menu's dependencies version: "^2.1.2" instead of "2.x" anti semver [email protected] ao rc-menu ao [email protected] use uxcore-menu's dependencies version: "^4.0.0" instead of "4.x" anti semver [email protected] ao rc-time-picker ao [email protected] use uxcore-calendar's dependencies version: "^2.1.2" instead of "2.x" [4/12] uxcore-menu@~1.4.1 installed at node_modules.1.4.3@uxcore-menu anti semver [email protected] ao rc-calendar ao [email protected] use uxcore-calendar's dependencies version: "^2.1.2" instead of "2.x" [5/12] uxcore-message@~0.2.6 installed at node_modules.0.2.6@uxcore-message [6/12] uxcore-calendar@~0.7.1 installed at node_modules.0.7.2@uxcore-calendar anti semver [email protected] ao [email protected] ao rc-tree ao [email protected] use uxcore-tree's dependencies version: "^2.1.2" instead of "2.x" anti semver [email protected] ao [email protected] ao rc-tree ao [email protected] use uxcore-tree's dependencies version: "^4.0.0" instead of "4.x" [7/12] @ali/uxcore-cascade-multi-select@~1.5.x installed at node_modules.1.5.3@@ali\uxcore-cascade-multi-select [8/12] uxcore-cascade-select@~0.2.0 installed at node_modules.0.2.3@uxcore-cascade-select [9/12] uxcore-select2@~0.4.2 installed at node_modules.0.4.5@uxcore-select2 [10/12] uxcore-table@~1.12.16 installed at node_modules.1.12.19@uxcore-table [11/12] uxcore-form@~1.8.13 installed at node_modules.1.8.14@uxcore-form [12/12] uxcore-dialog@~0.5.0 installed at node_modules.0.5.5@uxcore-dialog peerDependencies WARNING @ali/[email protected] ao [email protected] requires a peer of react@>=0.13.0 but none was installed All packages installed (92 packages installed from npm registry, used 3s, speed 369.29kB/s, json 129(250.67kB), tarball 885.64kB) Recently updated (since 2017-03-02): 8 packages (detail see file D:\sacpage\fis_sac\node_modules.recently_updates.txt) Today: a [email protected] (10:28:12) a @ali/[email protected] ao [email protected] (10:50:19) Building libraries... Time: 1859ms Asset Size Chunks Chunk Names uxcore.js 3.98 MB 0 [emitted] uxcore Minify file: D:\sacpage\fis_sac\dist\uxcore.js

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git pull origin daily/1.0.6 From http://gitlab.alibaba-inc.com/platform/fis_sac

  • branch daily/1.0.6 -> FETCH_HEAD Updating a3f67bd..6107d8a error: Your local changes to the following files would be overwritten by merge: dist/uxcore.js dist/uxcore.min.js src/lib/uxcore.js src/lib/uxcore.min.js Please commit your changes or stash them before you merge. Aborting

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git fetch --all Fetching origin

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git reset --hard origin/daily/1.0.6 HEAD is now at 6107d8a 2017-3-8 16:10 xiaoyi update

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git pull origin daily/1.0.6 From http://gitlab.alibaba-inc.com/platform/fis_sac

  • branch daily/1.0.6 -> FETCH_HEAD Already up-to-date.

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git status On branch daily/1.0.6 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)

    modified:   dist/app-en.js
    modified:   dist/app-zh-cn.js
    modified:   dist/applyforaccount-en.js
    modified:   dist/applyforaccount-zh-cn.js
    modified:   dist/demo-en.js
    modified:   dist/demo-zh-cn.js
    modified:   dist/home-en.js
    modified:   dist/home-zh-cn.js
    modified:   dist/menubar-en.js
    modified:   dist/menubar-zh-cn.js
    modified:   dist/rerun-en.js
    modified:   dist/rerun-zh-cn.js
    modified:   dist/tossledger-en.js
    modified:   dist/tossledger-zh-cn.js

Untracked files: (use "git add ..." to include in what will be committed)

    dist/jobview-en.js
    dist/jobview-zh-cn.js
    dist/jobview.css
    dist/jobview.html
    html/jobview.html
    src/pages/jobview/

no changes added to commit (use "git add" and/or "git commit -a")

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git add .

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git commit -m 'add jobview page wb-wt261136' [daily/1.0.6 eb88d91] add jobview page wb-wt261136 23 files changed, 625 insertions(+), 14 deletions(-) rewrite dist/applyforaccount-en.js (97%) rewrite dist/applyforaccount-zh-cn.js (98%) create mode 100644 dist/jobview-en.js create mode 100644 dist/jobview-zh-cn.js create mode 100644 dist/jobview.css create mode 100644 dist/jobview.html create mode 100644 html/jobview.html create mode 100644 src/pages/jobview/CascadeMultiSelect.less create mode 100644 src/pages/jobview/PageJobview.js create mode 100644 src/pages/jobview/PageJobview.less create mode 100644 src/pages/jobview/index.js

wb-wt261136@MININT-AOUKK2A MINGW64 /d/sacpage/fis_sac (daily/1.0.6) $ git push -u origin daily/1.0.6 Counting objects: 26, done. Delta compression using up to 4 threads. Compressing objects: 100% (25/25), done. Writing objects: 100% (26/26), 23.98 KiB | 0 bytes/s, done. Total 26 (delta 17), reused 0 (delta 0) remote: {"data":"success","code":200}????·2è¢?è??§??°?°?????3???????????èˉ·?¥??é?????????assets.alibaba-inc.com??èˉ|?è§http://www.atatech.org/articles/53341 To http://gitlab.alibaba-inc.com/platform/fis_sac.git 6107d8a..eb88d91 daily/1.0.6 -> daily/1.0.6 Branch daily/1.0.6 set up to track remote branch daily/1.0.6 from origin.

⚠️ **GitHub.com Fallback** ⚠️