git的簡單使用


 

 

 

 

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

user.email=liujianzuo@liujianzuo.com

加顏色  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 git@github.com:liujianzuo/demo.git

 

[root@mylab liujianzuo]#  git remote add origin git@github.com:liujianzuo/demo.git
[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不要占用 

https://gitlab.com 

[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

http://192.168.92.129/users/sign_in 

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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM