GIT learning notes

System version: CentOS Linux release 7.6.1810
ip: 192.168.3.58

git installation (1)

//Dependency library installation
2. # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
3. # yum install gcc perl-ExtUtils-MakeMaker

//Uninstall the older version of Git
4. # yum remove git

//Download the new version of git source package (I put it in the directory of / usr/local/git, which is my own directory of mkdir)
5. # cd git
6. # wget https://github.com/git/git/archive/v2.9.2.tar.gz
7. # tar -xzvf v2.9.2.tar.gz

git installation (2)

# cd git-2.9.2
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install

git installation (3)

vim /etc/profile  
export PATH="/usr/local/git/bin:$PATH"

source /etc/profile

ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack 
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack 

groupadd git
useradd git -g git
passwd git 

cd /home/git/
mkdir .ssh #New folder
chmod 700 .ssh 
touch .ssh/authorized_keys  #new file
chmod 600 .ssh/authorized_keys

git config --global user.name 'User name'
git config --global user.email 'E-mail address'
cat ~/.gitconfig(Configuration information)
//Set up system users

ssh-keygen -t rsa -C "git mailbox"

ssh -T -v git@github.com (Test connection)

Basic commands of git

1.mkdir demo
   cd  demo
     git init   Initialize warehouse

2.git config  user.name 'User name'
   git config  user.email 'E-mail address'
     cat .git/config
     //Create warehouse user

3.git status (git Situation)
On branch master
nothing to commit(No documents submitted), working tree clean(No files to operate)

4.touch 1.txt
5.git status
    On branch master
    Untracked files:
     (use "git add <file>..." to include in what will be committed)(Add files to staging area)

        1.txt

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

6.git add 1.txt  (Add to staging area)
7.[root@ansible demo]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   1.txt

8.git rm --cached 1.txt(Recall files from staging area)
9.[root@ansible demo]# git commit 1.txt (commit from staging area to local warehouse)
[master e188f9f]      Third submission
 1 file changed, 0 insertions(+), 0 deletions(-)(If a file changes, add 0 lines and decrease 0 lines)
 create mode 100644 1.txt   (Number)

10.[root@ansible demo]# vim 1.txt
[root@ansible demo]# git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   1.txt

no changes added to commit (use "git add" and/or "git commit -a")(You can add stay commit,It can also be direct commit,Because this is a file that I have modified.)

11.[root@ansible demo]# git commit 1.txt -m'1.txt append '(- m' add description information of this submission ')
[master 240925b] 1.txt Append
 1 file changed, 1 insertion(+)

12.[root@ansible demo]# Git log (view log)
commit 240925b819e16e5fe8c78eea0f03b77c87779e17(hash Index, the content of which is the following information)
Author: ding <ding@163.com>(Submission)
Date:   Tue Jun 25 12:07:47 2019 +0800(Time zone)

    1.txt Append

commit e188f9f91ee2783777cf86107d0b9bf9732bbcef
Author: ding <ding@163.com>
Date:   Tue Jun 25 11:58:29 2019 +0800

13[root@ansible demo]# git log --pretty=oneline
240925b819e16e5fe8c78eea0f03b77c87779e17 1.txt Append
e188f9f91ee2783777cf86107d0b9bf9732bbcef      Third submission
d864fa6441ba254ac7efa075ff92f5a477e3d1e0 ceshi1
0faa007d4f0aa882e073f1f82f33eba494b8f467 Test submission

[root@ansible demo]# git log --oneline
240925b 1.txt Append
e188f9f      Third submission
d864fa6 ceshi1
0faa007 Test submission

[root@ansible demo]# git reflog(head @ {move several steps to the current version})
240925b HEAD@{0}: commit: 1.txt Append
e188f9f HEAD@{1}: commit: Third submission
d864fa6 HEAD@{2}: commit: ceshi1
0faa007 HEAD@{3}: commit (initial): Test submission

14.Version forward / backward (via HEAD Pointer control) default HEAD Point to last commit
15.[root@ansible demo]# Git reset -- hard d864fa6 (forward and backward based on Index) (recommended)
HEAD is now at d864fa6 ceshi1
[root@ansible demo]# git reflog
d864fa6 HEAD@{0}: reset: moving to d864fa6
240925b HEAD@{1}: commit: 1.txt Append
e188f9f HEAD@{2}: commit: Third submission
d864fa6 HEAD@{3}: commit: ceshi1
0faa007 HEAD@{4}: commit (initial): Test submission

15.[root@ansible demo]# git reset --hard HEAD ^
16.[root@ansible demo]# git reset --hard HEAD~2

17.git reset --soft    (Indicates that the local library changes, and neither the cache nor the workspace changes.)
18.git reset --mixed   (Indicates that the local library and cache have changed, and the workspace remains unchanged.)

19.git diff HEAD [file name](View file modifications)
20.git diff HEAD^ [file name](View file encountered a version change)
21.git diff (View existing workspace modification records)
22.git diff HEAD (View all modification records)

git diff :  Comparison workspace(not git add)Temporary storage area(git add after)
git diff --cached: Contrast staging area(git add after)Version Library(git commit after)
git diff HEAD:  Comparison workspace(not git add)Version Library(git commit after)

23.gti branch -v (View branch)
24.git checkout [Branch name]   (Switch main branch)
25.git branch [Branch name]  (Create branch)

26.Before merging two branches, the same file and the same line have different file contents, which will cause conflicts during merging. Change to the desired file content and delete special symbols. again git add File, and git merge -m'Version information'Do not add file name
Command summary:
1.git status (view workspace and staging area)
2.git add "filename"
3git commit [filename] -m 'description information' (submit file to local library and add description)

GIT remote library

Set up a github'Account number
//Create a new project
//Local git remote add origin https://github.com/bob-dpx/doupo.git (take an alias)

[root@ansible doupo]# git remote -v (view remote library)
origin  https://github.com/bob-dpx/doupo.git (fetch)
origin  https://github.com/bob-dpx/doupo.git (push)

[root@ansible doupo]# Git push origin master
Username for 'https://github.com': bob-dpx
Password for 'https://bob-dpx@github.com':
Counting objects: 3, done.
Writing objects: 100% (3/3), 221 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bob-dpx/doupo.git
 * [new branch]      master -> master

[root@ansible doupo_yaol]# Git clone https://github.com/bob-dpx/doupo.git (clone to local)
Cloning into 'doupo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.

[root@ansible doupo_yaol]# ls
doupo
[root@ansible doupo_yaol]# cd doupo/
[root@ansible doupo]# ls
yanmeng.txt
[root@ansible doupo]# cat yanmeng.txt
//Leader: Xiao Yan
[root@ansible doupo]# Cat. Git / (no need to initialize the local library, clone has helped us initialize)
branches/    description  hooks/       info/        objects/     refs/
config       HEAD         index        logs/        packed-refs
[root@ansible doupo_yaol]# Git remote-v (clone has even built another name)
origin  git@github.com:bob-dpx/gitspace.git (fetch)
origin  git@github.com:bob-dpx/gitspace.git (push)

[root@ansible doupo]# git fetch origin master
[root@ansible doupo]# git checkout origin/master
[root@ansible doupo]# git merge origin/master
[root@ansible doupo]# git pull origin master

GIT joining new members

Click: setting - > collaborators - > enter the name of the invited member and assign the address in the link.
The invited members log in to github, paste the link address, and select the same one to join

GIT invites other teams to work

Team leader of other teams: fork a branch of his own, make changes in it, and then click pull request - > new pull request - > create pull request - > wait to be merged

On my own side: - > pull request - > files changed (see what changes have been made) - > merge pull request merge code

Build gitlab in CentOS 7.6

1.stay gitlab Download software package on official website
https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm
//Verify the file integrity with md5sum after downloading

2.Script writing
rpm-ivh gitlab-ce-12.0.2-ce.0.el7.x86_64.rpm
yum install -y curl policycoreutils-python openssh-server cronie
lokkit -s http -s ssh
yum install postfix
service postfix start
chkconfig postfix on
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce

3.Initializer
gitlab-ctl reconfigure(Generally within 4 minutes)

4.Page access

Keywords: Linux git ansible github GitLab

Added by lovely on Thu, 31 Oct 2019 11:57:20 +0200