多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
第一部分:在本地电脑上创建一个仓库 (如果是从gitlab上克隆仓库,这里省略操作) 1)创建本地仓库 ![](https://box.kancloud.cn/166464661c8b72dad6628f1d8ea798f9_688x587.png) ![](https://box.kancloud.cn/410930d525626959b558f3872c30114f_481x185.png) 或者(使用git命令如下) $ git init Initialized empty Git repository in E:/project/test01/.git/ (注意: 1、此时就在该目录下,生成一个.git隐藏文件 2、在linux系统上创建版本库,也是通过cd命令进入到指定目录,然后通过git init命令 2)配置git 姓名: $ git config --global user.name "louis1986" 邮箱: $ git config --global user.email "testgit@163.com" 差异颜色显示: $ git config --global color.ui true (注意:在linux系统上,也是通过以上几条命令进行配置的) 第二部分:git 的基本操作流程 git的三个重要的概念: working directory:工作区 staging area: 暂存区 git reposity: 版本库 * 在工作目录(工作区)中修改某些文件(例如我们在e:/project/test目录下新建一个文件) * 对已经修改的文件,通过git add命令保存到暂存区 * 对保存到暂存区的内容,通过git commit提交到本地版本库 演示:(以windows的git bash为例) 1)Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ touch readmine (在工作区上新建一个文件) Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ ll -a total 8 drwxr-xr-x 1 Administrator 197121 0 一月 26 11:32 ./ drwxr-xr-x 1 Administrator 197121 0 一月 26 11:20 ../ drwxr-xr-x 1 Administrator 197121 0 一月 26 11:32 .git/ -rw-r--r-- 1 Administrator 197121 0 一月 26 11:32 readmine Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ echo "hello world" > readmine (向这个文件里添加内容,或者你用编辑器编辑好也可以) Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git status (查看当前工作区里,git的状态) On branch master No commits yet Untracked files: (这种状态,表示该文件没有被版本库跟踪,必须要通过git add命令,才能被版本库追踪) (use "git add <file>..." to include in what will be committed) readmine ​ 第一部分:在本地电脑上创建一个仓库 (如果是从gitlab上克隆仓库,这里省略操作) 1)创建本地仓库 或者(使用git命令如下) $ git init Initialized empty Git repository in E:/project/test01/.git/ (注意:此时就在该目录下,生成一个.git隐藏文件) 2)配置git 姓名: $ git config --global user.name "louis1986" 邮箱: $ git config --global user.email "testgit@163.com" 差异颜色显示: $ git config --global color.ui true 第二部分:git 的基本操作流程 git的三个重要的概念: working directory:工作区 staging area: 暂存区 git reposity: 版本库 在工作目录(工作区)中修改某些文件(例如我们在e:/project/test目录下新建一个文件) 对已经修改的文件,通过git add命令保存到暂存区 对保存到暂存区的内容,通过git commit提交到本地版本库 演示:(以windows的git bash为例) 1)Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ touch readmine (在工作区上新建一个文件) Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ ll -a total 8 drwxr-xr-x 1 Administrator 197121 0 一月 26 11:32 ./ drwxr-xr-x 1 Administrator 197121 0 一月 26 11:20 ../ drwxr-xr-x 1 Administrator 197121 0 一月 26 11:32 .git/ -rw-r--r-- 1 Administrator 197121 0 一月 26 11:32 readmine Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ echo "hello world" > readmine (向这个文件里添加内容,或者你用编辑器编辑好也可以) Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git status (查看当前工作区里,git的状态) On branch master No commits yet Untracked files: (这种状态,表示该文件没有被版本库跟踪,必须要通过git add命令,才能被版本库追踪) (use "git add ..." to include in what will be committed) readmine nothing added to commit but untracked files present (use "git add" to track) Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git add readmine (添加到暂存区) warning: LF will be replaced by CRLF in readmine. The file will have its original line endings in your working directory. Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git status On branch master No commits yet Changes to be committed: (已经被版本库追踪,要通过git commit 提交到版本库) (use "git rm --cached ..." to unstage) new file: readmine Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git commit -m "add readmine file" [master (root-commit) b6f4b94] add readmine file 1 file changed, 1 insertion(+) create mode 100644 readmine Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git status (再次查看,发现该工作区里没有任何改变) On branch master nothing to commit, working tree clean Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git log (查看这次提交的日志) commit b6f4b94aa9f0c6aae7f774fc42da6798ea6b1ac8 (HEAD -> master) Author: louis test123@163.com Date: Fri Jan 26 11:35:12 2018 +0800 add readmine file Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git show b6f4b94aa9 查看本地有那些修改(在windows系统上这里最好用tortoiseGit查看) commit b6f4b94aa9f0c6aae7f774fc42da6798ea6b1ac8 (HEAD -> master) Author: louis test123@163.com Date: Fri Jan 26 11:35:12 2018 +0800 add readmine file diff --git a/readmine b/readmine new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/readmine @@ -0,0 +1 @@ +hello world Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) 2)然后我再次修改readline文件,看看跟第一次有什么区别 新的文件或目录,第一次查看状态是:Untracked files:(表示没有被版本库追踪),然后提交过一次后,第二次修改,查看状态,就发现是:Changes not staged for commit $ echo "good" >> readmine Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git status (发现这个文件修改) On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: readmine no changes added to commit (use "git add" and/or "git commit -a") Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git add readmine warning: LF will be replaced by CRLF in readmine. The file will have its original line endings in your working directory. Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git commit -m "second modify readmine" [master d0a1f54] second modify readmine 1 file changed, 1 insertion(+) Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) 3)再次修改文件,我们可以直接执行git commit命令,直接提交到版本库,不添加git add命令 $ echo "world" >> readmine Administrator@WIN-0JU14CFTKDB MINGW32 /e/project/test01 (master) $ git commit -a -m " third modify readmine" (添加-a -m) warning: LF will be replaced by CRLF in readmine. The file will have its original line endings in your working directory. [master 460c09f] third modify readmine 1 file changed, 1 insertion(+) (注意:以上命令在linux系统上,也可以执行的) 4)如果要提交到远程仓库(这里一定要慎重,因为提交到远程仓库,有问题,回滚会有一定的风险),所以一般情况下,例如开发工程师A,开发A模块,我们都会基于master主分支,创建一个A分支出来,然后开发每次提交到远程A分支上,经过测试确定没有问题后,然后在合并到主分支上 已连接9个文件被修改第二章:Git的基本概念.md