git的简单使用
发布日期:2021-08-18 00:51:49 浏览次数:2 分类:技术文章

本文共 22260 字,大约阅读时间需要 74 分钟。

 

 

 

 

Git-csm.com

安装git  http://www.git-scm.com/download

[liujianzuo@mylab ~]$ yum install git

已加载插件:fastestmirror, security

你需要以 root 身份执行此命令。

[liujianzuo@mylab ~]$ sudo su -

[root@mylab ~]# yum install git

已加载插件:fastestmirror, security

设置安装进程

Determining fastest mirrors

 * base: mirrors.yun-idc.com

 * extras: mirrors.opencas.cn

 * updates: mirrors.opencas.cn

base                                                                                                     | 3.7 kB     00:00     

extras                                                                                                   | 3.4 kB     00:00     

updates                                                                                                  | 3.4 kB     00:00     

解决依赖关系

--> 执行事务检查

---> Package git.x86_64 0:1.7.1-3.el6_4.1 will be 安装

--> 处理依赖关系 perl-Git = 1.7.1-3.el6_4.1,它被软件包 git-1.7.1-3.el6_4.1.x86_64 需要

--> 处理依赖关系 perl(Git),它被软件包 git-1.7.1-3.el6_4.1.x86_64 需要

--> 处理依赖关系 perl(Error),它被软件包 git-1.7.1-3.el6_4.1.x86_64 需要

--> 执行事务检查

---> Package perl-Error.noarch 1:0.17015-4.el6 will be 安装

---> Package perl-Git.noarch 0:1.7.1-3.el6_4.1 will be 安装

--> 完成依赖关系计算

 

依赖关系解决

 

================================================================================================================================

 软件包                         架构                       版本                                  仓库                      大小

================================================================================================================================

正在安装:

 git                            x86_64                     1.7.1-3.el6_4.1                       base                     4.6 M

为依赖而安装:

 perl-Error                     noarch                     1:0.17015-4.el6                       base                      29 k

 perl-Git                       noarch                     1.7.1-3.el6_4.1                       base                      28 k

 

事务概要

================================================================================================================================

Install       3 Package(s)

 

总下载量:4.7 M

Installed size: 15 M

确定吗?[y/N]y

下载软件包:

(1/3): git-1.7.1-3.el6_4.1.x86_64.rpm                                                                    | 4.6 MB     00:14     

(2/3): perl-Error-0.17015-4.el6.noarch.rpm                                                               |  29 kB     00:00     

(3/3): perl-Git-1.7.1-3.el6_4.1.noarch.rpm                                                               |  28 kB     00:00     

--------------------------------------------------------------------------------------------------------------------------------

总计                                                                                            308 kB/s | 4.7 MB     00:15     

运行 rpm_check_debug 

执行事务测试

事务测试成功

执行事务

  正在安装   : 1:perl-Error-0.17015-4.el6.noarch                                                                            1/3 

  正在安装   : perl-Git-1.7.1-3.el6_4.1.noarch                                                                              2/3 

  正在安装   : git-1.7.1-3.el6_4.1.x86_64                                                                                   3/3 

  Verifying  : git-1.7.1-3.el6_4.1.x86_64                                                                                   1/3 

  Verifying  : perl-Git-1.7.1-3.el6_4.1.noarch                                                                              2/3 

  Verifying  : 1:perl-Error-0.17015-4.el6.noarch                                                                            3/3 

 

已安装:

  git.x86_64 0:1.7.1-3.el6_4.1                                                                                                  

 

作为依赖被安装:

  perl-Error.noarch 1:0.17015-4.el6                              perl-Git.noarch 0:1.7.1-3.el6_4.1                             

 

完毕!

 

 

 

Git命令使用

 

设置用户名 邮箱名

[root@mylab ~]# git config --global user.name "liujianzuo"

[root@mylab ~]# git config --global user.email "liujianzuo@liujianzuo.com"

查看列表

[root@mylab ~]# git config --list

user.name=liujianzuo

加颜色  git config --global color.ui true

[root@mylab ~]# git config --global color.ui true

[root@mylab ~]# git config --list

user.name=liujianzuo

user.email=liujianzuo@liujianzuo.com

color.ui=true

Git 初始化项目目录 git init

[root@mylab ~]# mkdir liujianzuo

[root@mylab ~]# cd liujianzuo/

[root@mylab liujianzuo]# git init

Initialized empty Git repository in /root/liujianzuo/.git/

[root@mylab liujianzuo]# ls -la

总用量 12

drwxr-xr-x  3 root root 4096 11月 17 16:42 .

dr-xr-x---. 5 root root 4096 11月 17 16:42 ..

drwxr-xr-x  7 root root 4096 11月 17 16:42 .git

 

初始化后新建代码文件 并 查看状态 git status

[root@mylab liujianzuo]# echo "hehe" >>readme.txt

[root@mylab liujianzuo]# cat readme.txt 

hehe

[root@mylab liujianzuo]# git status

# On branch master

#

# Initial commit

#

# Untracked files:

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

#

#       readme.txt

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

添加到暂存区 git add

[root@mylab liujianzuo]# git add readme.txt 

[root@mylab liujianzuo]# git status         

# On branch master

#

# Initial commit

#

# Changes to be committed:

#   (use "git rm --cached <file>..." to unstage)

#

#       new file:   readme.txt

#

提交代码 并作注释说明 git commit

[root@mylab liujianzuo]# git commit -m "the first commit"

[master (root-commit) 31ac5e1] the first commit 提交序列码

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 100644 readme.txt

[root@mylab liujianzuo]# git status

# On branch master

nothing to commit (working directory clean)

[root@mylab liujianzuo]# echo -e "#!/bin/sh\necho "hehe"">> deploy.sh

-bash: !/bin/sh\necho: event not found

[root@mylab liujianzuo]# echo -e "#\!\/bin\/sh\necho "hehe"">> deploy.sh

[root@mylab liujianzuo]# cat deploy.sh 

#\!\/bin\/sh

echo hehe

[root@mylab liujianzuo]# git add deploy.sh 

[root@mylab liujianzuo]# git commit -m "2th commit"

[master fca8bc6] 2th commit

 1 files changed, 2 insertions(+), 0 deletions(-)

 create mode 100644 deploy.sh

[root@mylab liujianzuo]# ls -l

总用量 8

-rw-r--r-- 1 root root 23 11月 17 16:49 deploy.sh

-rw-r--r-- 1 root root  5 11月 17 16:44 readme.txt

查看提交的信息 git log

[root@mylab liujianzuo]# git log

commit fca8bc64d5ff941decef45ba96ec0023ddc7ef8e

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:50:32 2015 +0800

 

    2th commit

 

commit 31ac5e162b4f1bc6ca63ac69d22c3e462e5e4fe2

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:47:28 2015 +0800

 

    the first commit

[root@mylab liujianzuo]# echo "hehe">>readme.txt 

[root@mylab liujianzuo]# git status

# On branch master

# Changed but not updated:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#

#       modified:   readme.txt

#

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

第二次提交后查看 比较做出的改动 git diff

[root@mylab liujianzuo]# git diff readme.txt 

diff --git a/readme.txt b/readme.txt

index 91ca0fa..197cac2 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1 +1,2 @@

 hehe

+hehe

[root@mylab liujianzuo]# git add readme.txt

[root@mylab liujianzuo]# git commit -m "add 2 hehe"

[master f64e9e3] add 2 hehe

 1 files changed, 1 insertions(+), 0 deletions(-)

[root@mylab liujianzuo]# git log

commit f64e9e3b373c06162807267e7e451c280d45e3e1

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:52:12 2015 +0800

 

    add 2 hehe

 

commit fca8bc64d5ff941decef45ba96ec0023ddc7ef8e

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:50:32 2015 +0800

 

    2th commit

 

commit 31ac5e162b4f1bc6ca63ac69d22c3e462e5e4fe2

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:47:28 2015 +0800

 

the first commit

 

版本 回滚 HEAD当前版本 ^上一个版本。如果是上上个版本^^则是两个 一次类推 git reset --hard HEAD^

[root@mylab liujianzuo]# git reset --hard HEAD^

HEAD is now at fca8bc6 2th commit

[root@mylab liujianzuo]# cat readme.txt 

hehe

[root@mylab liujianzuo]# git log

commit fca8bc64d5ff941decef45ba96ec0023ddc7ef8e

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:50:32 2015 +0800

 

    2th commit

 

commit 31ac5e162b4f1bc6ca63ac69d22c3e462e5e4fe2

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Tue Nov 17 16:47:28 2015 +0800

 

the first commit

查看提交历史 序列码 git reflog

[root@mylab liujianzuo]# git reflog

fca8bc6 HEAD@{0}: HEAD^: updating HEAD

f64e9e3 HEAD@{1}: commit: add 2 hehe

fca8bc6 HEAD@{2}: commit: 2th commit

31ac5e1 HEAD@{3}: commit (initial): the first commit

指定序列码 回滚 git reset --hard 序列码 一定要知道回滚才能回滚

[root@mylab liujianzuo]# git reset --hard 31ac5e1

HEAD is now at 31ac5e1 the first commit

[root@mylab liujianzuo]# cat readme.txt 

hehe

[root@mylab liujianzuo]# ls

readme.txt

 

 

 

Git 暂存区 工作区概念

只有放在暂存区才能commit 提交  工作区放到暂存区必须要add

 

 

个人机器上生成 key

[root@mylab liujianzuo]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

bd:13:76:51:cb:fa:c9:c8:81:52:16:d9:0e:0a:7e:a7 root@mylab

The key's randomart image is:

+--[ RSA 2048]----+

|          .o  .  |

|      .   o..o . |

|     . . .oo. o  |

|      . o+...o   |

|       .So= +    |

|        Eo = = . |

|          o o +  |

|           .     |

|                 |

+-----------------+

[root@mylab liujianzuo]# ls /root/.ssh/

id_rsa  id_rsa.pub

[root@mylab liujianzuo]# ls /root/.ssh/ -l

总用量 8

-rw------- 1 root root 1675 11月 17 17:35 id_rsa

-rw-r--r-- 1 root root  392 11月 17 17:35 id_rsa.pub

 

[root@mylab liujianzuo]# cat /root/.ssh/id_rsa.pub 

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtAFn1en2i7cYkr8Ppo20jJG0Biu1icHHUx2NNGXXqZuRFmk07J0cbuoU7I8UcZg/d4bp7yubcFTnpbrgBUpHx5qF/xvI/fb5zPvNYRF7lJmHWEOYS9eMZeaZznH64nbLiQwg/ztvxyUt5FiGQ9Cy589lCO6E7yZqtY4/CcDBF5MF6dt0MMyl2Ier5PlwDSn1BsnYsFKo/Co81nEQVgTTtC0UCV4JDMjhmwgQUf5LTCt2/LhGqVCKcksNIxPQnIvxcAZhwvkULfh+k4hcsEe4lt7dqbG/XtCLyMlXW43twhHWdaV9fPbEgr+79Ac1mNzH5gRtGuyzuANrHP+iJxHBLQ== root@mylab

[root@my

 

 

 

 

添加远程参考 git remote add origin 

 

[root@mylab liujianzuo]#  git remote add origin [root@mylab liujianzuo]# cat .git/config 

[core]

        repositoryformatversion = 0

        filemode = true

        bare = false

        logallrefupdates = true

[remote "origin"]

        url = git@github.com:liujianzuo/demo.git

        fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]

        remote = origin

        merge = refs/heads/master

 

 

提交代码到 自己的项目   注意 先 git pull origin master  再 push

[root@mylab liujianzuo]# git pull

warning: no common commits

remote: Counting objects: 4, done.

remote: Compressing objects: 100% (4/4), done.

Unpacking objects: 100% (4/4), done.

remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0

From github.com:liujianzuo/demo

 * [new branch]      master     -> origin/master

You asked me to pull without telling me which branch you

want to merge with, and 'branch.master.merge' in

your configuration file does not tell me, either. Please

specify which branch you want to use on the command line and

try again (e.g. 'git pull <repository> <refspec>').

See git-pull(1) for details.

 

If you often merge with the same branch, you may want to

use something like the following in your configuration file:

 

    [branch "master"]

    remote = <nickname>

    merge = <remote-ref>

 

    [remote "<nickname>"]

    url = <url>

    fetch = <refspec>

 

See git-config(1) for details.

[root@mylab liujianzuo]# git pull origin master

From github.com:liujianzuo/demo

 * branch            master     -> FETCH_HEAD

Merge made by recursive.

 .gitignore |   57 +++++++++++++++++

 LICENSE    |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 2 files changed, 259 insertions(+), 0 deletions(-)

 create mode 100644 .gitignore

 create mode 100644 LICENSE

[root@mylab liujianzuo]# ll -a

总用量 32

drwxr-xr-x  3 root root  4096 11月 17 17:45 .

dr-xr-x---. 6 root root  4096 11月 17 17:35 ..

drwxr-xr-x  8 root root  4096 11月 17 17:45 .git

-rw-r--r--  1 root root   702 11月 17 17:45 .gitignore

-rw-r--r--  1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r--  1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# git push -u origin master

Counting objects: 12, done.

Compressing objects: 100% (5/5), done.

Writing objects: 100% (11/11), 966 bytes, done.

Total 11 (delta 0), reused 0 (delta 0)

To git@github.com:liujianzuo/demo.git

   381a21e..5eb0269  master -> master

Branch master set up to track remote branch master from origin.

 

克隆别人项目的代码

[root@mylab liujianzuo]# cd /tmp/

[root@mylab tmp]# ls

[root@mylab tmp]# git clone git@github.com:liujianzuo/demo.git

Initialized empty Git repository in /tmp/demo/.git/

Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.

remote: Counting objects: 15, done.

remote: Compressing objects: 100% (9/9), done.

remote: Total 15 (delta 1), reused 11 (delta 0), pack-reused 0

Receiving objects: 100% (15/15), 5.36 KiB, done.

Resolving deltas: 100% (1/1), done.

[root@mylab tmp]# ls

demo

[root@mylab tmp]# cd demo/

[root@mylab demo]# ls

LICENSE  readme.txt

[root@mylab demo]# 

 

 

 

 

搭建免费 git 仓库即gitlab    收费版本的git不用

最好用个干净的系统  端口80不要占用 

 

[root@mylab liujianzuo]# ls

gitlab-ce-7.12.2-omnibus-1.x86_64.rpm

[root@mylab liujianzuo]# rpm -ivh gitlab-ce-7.12.2-omnibus-1.x86_64.rpm 

Preparing...                ########################################### [100%]

   1:gitlab-ce              ########################################### [100%]

hostname: 未知的主机

gitlab: Thank you for installing GitLab!

gitlab: Configure and start GitLab by running the following command:

gitlab: 

gitlab: sudo gitlab-ctl reconfigure

gitlab: 

gitlab: GitLab should be reachable at http://gitlab.example.com

gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file

gitlab: And running reconfigure again.

gitlab: 

gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme

gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

gitlab: 

gitlab: 

gitlab: If you just upgraded from GitLab 7.9 or earlier, please run the following

gitlab: command:

gitlab: 

gitlab: sudo ln -sf   /opt/gitlab/bin/gitlab-ctl   /opt/gitlab/bin/gitlab-rake   /opt/gitlab/bin/gitlab-rails   /opt/gitlab/bin/gitlab-ci-rake   /opt/gitlab/bin/gitlab-ci-rails  /usr/bin/

[root@mylab liujianzuo]# 

 

从gitlab上克隆项目 登录gitlab的账户名密码

git clone http://username:password@HOST_IP/项目.git 

 

Windows  下的 sourcetree软件工具  bitbucket小团队 5免费git

 

 

操作命令

配置并启动GitLab

打开/etc/gitlab/gitlab.rb,将external_url = 'http://git.example.com'修改为自己的IP地址:http://xxx.xx.xxx.xx,,然后执行下面的命令,对GitLab进行编译。

全选复制放进笔记

sudo gitlab-ctl reconfigure

[root@mylab liujianzuo]# gitlab-ctl reconfigure

Starting Chef Client, version 12.4.0.rc.0

resolving cookbooks for run list: ["gitlab"]

Synchronizing Cookbooks:

  - gitlab

  - package

  - runit

Compiling Cookbooks...

 

1. Install and configure the necessary dependencies

 

If you install Postfix to send email please select 'Internet Site' during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server. If you wish to use Exim, please configure it as an SMTP server.

 

On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.

在Centos 6 和 7 中,以下的命令将会打开HTTP和SSH在系统防火墙中的可访问权限。

sudo yum install curl openssh-server postfix cronie

sudo service postfix start

sudo chkconfig postfix on

sudo lokkit -s http -s ssh # open up the firewall for HTTP and SSH requests

/etc/init.d/iptables stop

 

 

4. Browse to the hostname and login

 

Username: root 

Password: 5iveL!fe

 

配置GitLab的默认发信邮箱

 

GitLab中使用postfix进行邮件发送。因此,可以卸载系统中自带的sendmail

使用yum list installed查看系统中是否存在sendmail,若存在,则使用yum remove sendmail指令进行卸载。

测试系统是否可以正常发送邮件。

echo "Test mail from postfix" | mail -s "Test Postfix" xxx@xxx.com

注:上面的xxx@xxx.com为你希望收到邮件的邮箱地址。

当邮箱收到系统发送来的邮件时,将系统的地址复制下来,如:root@iZ23syflhhzZ.localdomain,打开/etc/gitlab/gitlab.rb,

 

# gitlab_rails['gitlab_email_from'] = 'gitlab@example.com' 

修改为

 

gitlab_rails['gitlab_email_from'] = 'root@iZ23syflhhzZ.localdomain' 

保存后,执行sudo gitlab-ctl reconfigure重新编译GitLab。如果邮箱的过滤功能较强,请添加系统的发件地址到邮箱的白名单中,防止邮件被过滤。

 

Note:系统中邮件发送的日志可通过`tail /var/log/maillog`命令进行查看。

 

安装过程中出现的问题

 

在浏览器中访问GitLab出现502错误

原因:内存不足。

 

解决办法:检查系统的虚拟内存是否随机启动了,如果系统无虚拟内存,则增加虚拟内存,再重新启动系统。

 

80端口冲突

原因:Nginx默认使用了80端口。

 

解决办法:为了使NginxApache能够共存,并且为了简化GitLabURL地址,Nginx端口保持不变,修改Apache的端口为4040。这样就可以直接用使用ip访问Gitlab。而禅道则可以使用4040端口进行访问,像这样:xxx.xx.xxx.xx:4040/zentao。具体修改的地方在/etc/httpd/conf/httpd.conf这个文件中,找到Listen 80这一句并将之注释掉,在底下添加一句Listen 4040,保存后执行service httpd restart重启apache服务即可。

 

#Listen 80 

Listen 4040 

8080端口冲突

原因:由于unicorn默认使用的是8080端口。

 

解决办法:打开/etc/gitlab/gitlab.rb,打开# unicorn['port'] = 8080的注释,将8080修改为9090,保存后运行sudo gitlab-ctl reconfigure即可。

 

STMP设置

配置无效,暂时不知道原因。

 

GitLab头像无法正常显示

原因:gravatar被墙

解决办法:

编辑 /etc/gitlab/gitlab.rb,将

#gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'

修改为:

 

gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'

然后在命令行执行:

 

sudo gitlab-ctl reconfigure 

sudo gitlab-rake cache:clear RAILS_ENV=production

 

分支的管理

方法创建后并切换 git branch dev git checkout dev

[root@mylab liujianzuo]# git branch dev  # 先创建  

You have new mail in /var/spool/mail/root

切换分支 git checkout dev

[root@mylab liujianzuo]# git checkout dev #再切换

Switched to branch 'dev'

查看当前分支 git branch

[root@mylab liujianzuo]# git branch  #查看当前分支

* dev

  master

[root@mylab liujianzuo]# ll

总用量 16

-rw-r--r-- 1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r-- 1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# echo "ehhheeheheheh" >dev.txt  #新建代码文件

[root@mylab liujianzuo]# git add dev.txt  # 添加到暂存区

[root@mylab liujianzuo]# git commit -m "add dev.txt" #提交

[dev e5b16a2] add dev.txt

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 100644 dev.txt

[root@mylab liujianzuo]# ll

总用量 20

-rw-r--r-- 1 root root    14 11月 20 17:03 dev.txt

-rw-r--r-- 1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r-- 1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# git checkout master #切换到 主支

Switched to branch 'master'

[root@mylab liujianzuo]# ll  #由于是在分支建立的devTxt 所以切换到主后没有文件 需要merge将分支的提交过来

总用量 16

-rw-r--r-- 1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r-- 1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# git checkout master

Already on 'master'

将分支合并到主支  提交哪个分支必须 不能在此分支 git merge

[root@mylab liujianzuo]# git merge dev   #提交到分支

Updating 5eb0269..e5b16a2

Fast-forward

 dev.txt |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 100644 dev.txt

[root@mylab liujianzuo]# ll

总用量 20

-rw-r--r-- 1 root root    14 11月 20 17:04 dev.txt

-rw-r--r-- 1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r-- 1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# git branch

  dev

* master

[root@mylab liujianzuo]# git brach -d dev^C

[root@mylab liujianzuo]# echo 123>>dev.txt 

 

You have new mail in /var/spool/mail/root

第二种创建分支 git checkout -b test

[root@mylab liujianzuo]# git checkout -b test #直接创建分支并切换分支

Switched to a new branch 'test'

[root@mylab liujianzuo]# git branch #查看分支

  dev

  master

* test

[root@mylab liujianzuo]# ll

总用量 20

-rw-r--r-- 1 root root    14 11月 20 17:04 dev.txt

-rw-r--r-- 1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r-- 1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# cat dev.txt  #查看新分支下的文件

ehhheeheheheh

[root@mylab liujianzuo]# echo "sdsdf" >>dev.txt  #修改该文件 

[root@mylab liujianzuo]# git add dev.txt  #添加暂存区 

[root@mylab liujianzuo]# git commit -m "change dev.txt testbranch" #提交

[test 0f42c30] change dev.txt testbranch

 1 files changed, 1 insertions(+), 0 deletions(-)

[root@mylab liujianzuo]# git checkout master  #切换到主分支

Switched to branch 'master'

Your branch is ahead of 'origin/master' by 1 commit.

[root@mylab liujianzuo]# echo "master" >> dev.txt  #更改主支文件

[root@mylab liujianzuo]# git add dev.txt  #添加

[root@mylab liujianzuo]# git commit -m "master change "#提交

[master 7ca637b] master change

 1 files changed, 1 insertions(+), 0 deletions(-)

[root@mylab liujianzuo]# git merge test  #我们合并 新建的分支   但是冲突  因为我在分支改过 文件   主支也改过 所以冲突

Auto-merging dev.txt

CONFLICT (content): Merge conflict in dev.txt

Automatic merge failed; fix conflicts and then commit the result.

[root@mylab liujianzuo]# cat dev.txt  #查看

ehhheeheheheh

<<<<<<< HEAD

master

=======

sdsdf

>>>>>>> test

[root@mylab liujianzuo]# echo "ehhheeheheheh" > dev.txt  #重新修改文件

You have new mail in /var/spool/mail/root

[root@mylab liujianzuo]# git add dev.txt      #重新添加            

[root@mylab liujianzuo]# git commit -m "master  change 2 " #提交

[master 9bd8581] master  change 2

[root@mylab liujianzuo]# git merge test #再次合并

Already up-to-date.

[root@mylab liujianzuo]# ll

总用量 20

-rw-r--r-- 1 root root    14 11月 20 17:11 dev.txt

-rw-r--r-- 1 root root 11358 11月 17 17:45 LICENSE

-rw-r--r-- 1 root root    29 11月 17 17:24 readme.txt

[root@mylab liujianzuo]# cat readme.txt 

hehe

woshi hehe

3 woshi hehe

[root@mylab liujianzuo]# cat dev.txt 

ehhheeheheheh

[root@mylab liujianzuo]# git push origin dev

Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.

Counting objects: 4, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 340 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To git@github.com:liujianzuo/demo.git

 * [new branch]      dev -> dev

[root@mylab liujianzuo]# git push origin test

Counting objects: 5, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 275 bytes, done.

Total 3 (delta 1), reused 0 (delta 0)

To git@github.com:liujianzuo/demo.git

 * [new branch]      test -> test

 

 

打标签 tag

[root@mylab liujianzuo]# git branch

  dev

* master

  test

[root@mylab liujianzuo]# git tag v1.0

[root@mylab liujianzuo]# git tag

v1.0

[root@mylab liujianzuo]# git show

commit 9bd8581dd26a77255733b4b4b8431af4cdc9ff24

Merge: 7ca637b 0f42c30

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Fri Nov 20 17:11:26 2015 +0800

 

    master  change 2

 

diff --cc dev.txt

index 227ecc9,8a36985..2f0c62b

--- a/dev.txt

+++ b/dev.txt

@@@ -1,2 -1,2 +1,1 @@@

  ehhheeheheheh

- master

 -sdsdf

You have new mail in /var/spool/mail/root

[root@mylab liujianzuo]# git show v1.00

fatal: ambiguous argument 'v1.00': unknown revision or path not in the working tree.

Use '--' to separate paths from revisions

[root@mylab liujianzuo]# git show v1.0

commit 9bd8581dd26a77255733b4b4b8431af4cdc9ff24

Merge: 7ca637b 0f42c30

Author: liujianzuo <liujianzuo@liujianzuo.com>

Date:   Fri Nov 20 17:11:26 2015 +0800

 

    master  change 2

 

diff --cc dev.txt

index 227ecc9,8a36985..2f0c62b

--- a/dev.txt

+++ b/dev.txt

@@@ -1,2 -1,2 +1,1 @@@

  ehhheeheheheh

- master

 -sdsdf

[root@mylab liujianzuo]# git push origin v1.0

Counting objects: 8, done.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (4/4), 448 bytes, done.

Total 4 (delta 1), reused 0 (delta 0)

To git@github.com:liujianzuo/demo.git

 * [new tag]         v1.0 -> v1.0

[root@mylab liujianzuo]# git checkout v1.0

Note: checking out 'v1.0'.

 

You are in 'detached HEAD' state. You can look around, make experimental

changes and commit them, and you can discard any commits you make in this

state without impacting any branches by performing another checkout.

 

If you want to create a new branch to retain commits you create, you may

do so (now or later) by using -b with the checkout command again. Example:

 

  git checkout -b new_branch_name

 

HEAD is now at 9bd8581... master  change 2

[root@mylab liujianzuo]# cat .gitignore 

 

 

Git 代码的 格式显示 必须叫md格式

[root@mylab liujianzuo]# cat HELP_MACDOWN.md 

# HELP 1 ji biaoti

## gan sha 2 ji biaoti

 

*** sange * shi fenge fu

 

* shi

*you

* lie

*biao

 

> war

 

[unixhot](http://www.unixhot.com)

 

![liujianzuo](http://www.igo100.cc/images/logo.jpg)

 

        while true:

          do echo hehe;

        Done

 

[root@mylab liujianzuo]# git add HELP_MACDOWN.md 

[root@mylab liujianzuo]# git commit -m "macdown11"          

[master 939f61b] macdown11

 1 files changed, 19 insertions(+), 0 deletions(-)

 create mode 100644 HELP_MACDOWN.md

[root@mylab liujianzuo]# git push -u origin master          

Counting objects: 3, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 233 bytes, done.

Total 2 (delta 1), reused 0 (delta 0)

To git@github.com:liujianzuo/demo.git

   1ae3b0f..939f61b  master -> master

Branch master set up to track remote branch master from origin.

转载于:https://www.cnblogs.com/liujianzuo888/p/4994617.html

转载地址:https://blog.csdn.net/weixin_30872733/article/details/99331652 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:实验2-2-8 阶梯电价
下一篇:单例模式Singleton

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月15日 17时40分21秒