git团队协作(一)

git团队协作(一)

前言:安装gitlab之后,必须开启80端口和ssh的端口才能正常工作。如果想限制非法ip的访问,可以到服务配置文件里面进行修改,ssh也可以通过修改/etc/hosts.allow和/etc/hosts.deny文件做限制

1、创建本地仓库

创建起点:

一个克隆的仓库
一个文件未被跟踪的文件夹
一个空目录

以windows操作系统为例:
在你安装好本地的git环境之后,右击鼠标,打开git bash的工具:
gitbash界面

创建一个文件夹,用于存储你所有的杨丽仓库:

laodiao@xielinrui MINGW64 ~/Desktop (master)
$ mkdir gitdemo
laodiao@xielinrui MINGW64 ~/Desktop (master)
$ ll
laodiao@xielinrui MINGW64 ~/Desktop (master)
$ cd gitdemo/
laodiao@xielinrui MINGW64 ~/Desktop/gitdemo (master)

2、克隆已有的项目

进入到代码托管系统上,本例以gitlab为例:
gitlab1

复制gitlab中仓库url的地址(以.git结尾)
命令:

git clone url

要点:创建项目克隆将会下载仓库中所有的父本及其提交历史,他还会记住你下载代码的地方,将远程代码托管服务器设置为跟踪仓库。以备以后想要检查更新,并下载到你的本地仓库。

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo (master)
$ git clone https://git.zhangliao.net/zhangliao/server.git
Cloning into 'server'...

如果这个.git项目是私密的,此时会弹出填写身份认证信息的界面,只有身份认证成功了才能正常clone。详细结果如下:


laodiao@xielinrui MINGW64 ~/Desktop/gitdemo (master)
$ git clone https://git.zhangliao.net/zhangliao/server.git
Cloning into 'server'...
remote: Counting objects: 2477, done.
remote: Compressing objects: 100% (46/46), done.
remote: Total 2477 (delta 16), reused 0 (delta 0)
Receiving objects: 100% (2477/2477), 7.54 MiB | 123.00 KiB/s, done.
Resolving deltas: 100% (933/933), done.
laodiao@xielinrui MINGW64 ~/Desktop/gitdemo (master)
$ ll
total 4
drwxr-xr-x 1 laodiao 197609 0 515 12:51 xxxxx/

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo (master)
$ cd xxxxx/

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo/xxxxx(master)
$ ll
total 46
drwxr-xr-x 1 laodiao 197609     0 515 12:51 xxxxxxx/
drwxr-xr-x 1 laodiao 197609     0 515 12:51 xxxxxx/
-rw-r--r-- 1 laodiao 197609 21709 515 12:51 xxxx.sql
-rw-r--r-- 1 laodiao 197609  1644 515 12:51 xxxx.txt
drwxr-xr-x 1 laodiao 197609     0 515 12:51 xxx/
-rw-r--r-- 1 laodiao 197609  1825 515 12:51 xxxxxx.bat
-rw-r--r-- 1 laodiao 197609    52 515 12:51 xxxxx.md
-rw-r--r-- 1 laodiao 197609     6 515 12:51 xxxxxx.txt

如果你把这个陌路弄得面目全非,删除文件夹并重新运行clone命令即可。

3、将已有项目迁移至git
还是到我们刚刚那个页面,下载仓库的压缩包
gitlab2

下载完成后,解压项目到新建的文件夹下:

mkdir gitdemo2

然后使用init指令来创建一个git仓库,git将会自动感知这个目录中(包括子目录中)的所有文件,从而确保你是在项目的根目录下运行init命令

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo2/xxxxx(master)
$ git init
Initialized empty Git repository in C:/Users/laodiao/Desktop/gitdemo2/xxxxx/.git/

使用status指令来检查仓库当前的状态:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo2/xxxxx (master)
$ git status
On branch master

Initial commit

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

        "xxx\350\277\236\346\216\245\350\277\207\347\250\213.txt"
        xxxx.md
        xxxx/
        xxxxxx/
        xxxxxxx.sql
        xxxxxxx/
        xxxxxxxx.bat
        "\165\253\253\332\274\272\365\243\246\332\217\243\350\233\254\312\265\232.txt"

nothing added to commit but untracked files present (use "git add" to track)

git告诉我们下一步是添加你想要跟踪的文件,刚刚是做的初始化仓库的操作。
所以,使用add指令将仓库中所有文件添加至暂存区:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo2/xxxxx(master)
$ git add --all
warning: LF will be replaced by CRLF in xxxxx.txt.
The file will have its original line endings in your working directory.
......

使用status指令继续查看git的提示:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo2/xxxxx (master)
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

      new file:   README.md
      ......

现在你得文件已经添加到本地仓库中,可以使用commit指令将你当前的状态保存到仓库中:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo2/xxxxx(master)
$ git commit -m "initial import of all project files"
[master (root-commit) 56b205f] initial import of all project files
 706 files changed, 292232 insertions(+)
 create mode 100644 README.md
 ......

你的项目文件现在已经处于版本控制下。

4、查看历史记录

log命令会按时间倒序输出仓库中提交消息的完整历史记录


laodiao@xielinrui MINGW64 ~/Desktop/gitdemo2/server (master)
$ git log
commit 56b205f12b2cc1b9d5e64ceee7c2b23d8e1cbffc
Author: unknown <xielinrui>
Date:   Tue May 15 13:19:26 2018 +0800

    initial import of all project files

5、使用分支工作

列出所有文职,可以使用branch命令:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo/xxxxx (master)
$ git branch --list
* master

列出所有分支:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo/xxxxx (master)
$ git branch --all
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/xxxxxxxxx
  remotes/origin/master

*代表你当前正在查看的分支,剩下以 r e m o t e s / o r i g i n 开头的分支表示不在本地
列出远程分支:

$ git branch --remote
  origin/HEAD -> origin/master
  origin/xxxxxxxxx
  origin/master

更新远程分支列表:

git fetch

猜你喜欢

转载自blog.csdn.net/xielinrui123/article/details/80321701
今日推荐