git团队协作(二)

git团队协作(二)

上一篇我们能够进行有效的从获取远程的仓库,本篇讲解关于简单使用的方法

,连接之前使用git remote –verbose指令查看连接至你当前仓库的远程仓库。

$ git remote --verbose
origin  https://github.com/xielinrui/web.git (fetch)
origin  https://github.com/xielinrui/web.git (push)

然后,使用git remote add origin来连接远程仓库:

$ git remote add origin https://github.com/xielinrui/web.git
fatal: remote origin already exists.

我这里只是做一个示范,如果本身存在远程仓库,就不需要再次去添加远程仓库了。

到目录下创建一个hosts.allow的文件,写上:

sshd:192.168.219.1:allow
创建一个hosts.deny文件,写上:
sshd:ALL:deny

然后使用之前的方法,将这个文件加入到本地仓库中:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ ll
total 3
-rw-r--r-- 1 laodiao 197609  25 515 14:35 hosts.allow
-rw-r--r-- 1 laodiao 197609  14 515 14:36 hosts.deny
-rw-r--r-- 1 laodiao 197609 115 515 13:48 README.txt

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git add hosts.*
warning: LF will be replaced by CRLF in hosts.allow.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in hosts.deny.
The file will have its original line endings in your working directory.

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git commit -m "ssh限制远程登录Ip"
[master 3557142] ssh限制远程登录Ip
 2 files changed, 2 insertions(+)
 create mode 100644 hosts.allow
 create mode 100644 hosts.deny

查看日志:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git log
commit 3557142d51859d96633e37b6a90dcb43c70e3f2a
Author: unknown <xielinrui>
Date:   Tue May 15 14:37:44 2018 +0800

    ssh限制远程登录Ip

commit 89571b00a3caa793c0aa9bf359fca4a7bd373de6
Author: unknown <xielinrui>
Date:   Tue May 15 13:49:35 2018 +0800

    Initial import readmetxt

使用push指令到远程仓库:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': xielinrui
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 376 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/xielinrui/web.git
   89571b0..3557142  master -> master
Branch master set up to track remote branch master from origin.

到github远程仓库查看,结果如下:
github1

结果如图表明上传成功。

当我们对刚刚上传的文件,做了一点点修改之后,该如何操作呢?
例如在hosts.allow文件后面添加:

sshd:192.168.0.0/16:allow

可以使用git add –update指令来更新:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ vi hosts.allow

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git add --update
warning: LF will be replaced by CRLF in hosts.allow.
The file will have its original line endings in your working directory.

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git commit -m "ssh允许某个网段访问,避免因动态ip引起自身登录不了的问题"
[master 67492ae] ssh允许某个网段访问,避免因动态ip引起自身登录不了的问题
 1 file changed, 1 insertion(+)

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': xielinrui
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 428 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/xielinrui/web.git
   3557142..67492ae  master -> master
Branch master set up to track remote branch master from origin.

效果如下:
github2
更新之后,展示上有区别和对比
github3

当我们想创建一个分支的时候,可以使用:

git branch 分支名

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git branch --all
* master
  remotes/origin/master

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git branch demo

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git branch --all
  demo
* master
  remotes/origin/master

*号表示我们目前正处于master分支上面,可以使用

git checkout 分支名
来改变我们目前处于的分支:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git branch --all
  demo
* master
  remotes/origin/master

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git checkout demo
Switched to branch 'demo'

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ git branch --all
* demo
  master
  remotes/origin/master

现在有了本地分支,可以通过指令

git push –set-upstream 远程仓库 本地分支

来进行上传:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ git push --set-upstream origin demo
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': xielinrui
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/xielinrui/web.git
 * [new branch]      demo -> demo
Branch demo set up to track remote branch demo from origin.

github5

然后在demo分支下新建一个文件,进行提交:


laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ touch about_https.txt

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ vi about_https.txt

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ git add about_https.txt
warning: LF will be replaced by CRLF in about_https.txt.
The file will have its original line endings in your working directory.

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ git commit -m "about https"
[demo 15fd3d2] about https
 1 file changed, 1 insertion(+)
 create mode 100644 about_https.txt

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ git push -u origin demo
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': xielinrui
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 705 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/xielinrui/web.git
   3557142..15fd3d2  demo -> demo
Branch demo set up to track remote branch demo from origin.

这个是master分支
github7
很明显,这上面没有提交的文件
再来看看demo分支:
github8
效果很明显
然后,尝试把demo分支中的文件合并到master分支中:

git checkout master
git merge demo

示例效果:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (demo)
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git merge demo
Merge made by the 'recursive' strategy.
 about_https.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 about_https.txt

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git push --set-upstream origin master
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': xielinrui
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 270 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/xielinrui/web.git
   67492ae..91b77f2  master -> master
Branch master set up to track remote branch master from origin.

github9
可以发现目前master分支中也有about_https文件了

对于与项目无关的文件,可以创建一个全局设置来忽略这些文件

git config –global core.excludesfile ./.gitignore

示例:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ git config --global core.excludesfile ./.gitignore

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ ll
total 3
-rw-r--r-- 1 laodiao 197609  51 5月  15 14:57 hosts.allow
-rw-r--r-- 1 laodiao 197609  14 5月  15 14:36 hosts.deny
-rw-r--r-- 1 laodiao 197609 115 5月  15 13:48 README.txt

目前文件夹下面还没有那个文件,所以需要自己手动创建一个:

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ vi ./.gitignore

按行填入不需要上传的文件即可

laodiao@xielinrui MINGW64 ~/Desktop/gitdemo3/web (master)
$ ls -a
./  ../  .git/  .gitignore  hosts.allow  hosts.deny  README.txt

然后使用ls -a就可以看见存在于当前目录下了。

猜你喜欢

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