Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Code management platform-git

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Installation: yum install-y git

Create a directory: mkdir / data/gitroot

Enter: cd / data/gitroot

Initialize: git init / / initialize the warehouse

Write a test file: echo-e "123\ naaa\ n456\ nbbb" > 1.txt / / create a new file

Add: git add 1.txt// adds 1.txt to the warehouse

Submit: git commit-m "add new file 1.txt" / / add. Commit is required to actually submit the file to the git warehouse.

Change 1.txt again

Check status git status / / check the status in the current warehouse, such as whether there are any changed files

Git diff 1.txt / / you can compare what 1.txt has modified this time, and compare the version in the warehouse.

Version fallback

Change 1.txt a few more times, and then add,commit

Git log// views all submission records

Git log-- pretty=oneline// display on one line

Git reset-- hard fe063f19ab// fallback version, followed by a string that is abbreviated

Undo the modification

Rm-f 1.txt// accidentally deleted 1.txt

Git checkout-1.txt// restore 1.txt

If the 1.txt file is modified and there is no commit after add, you want to go back to the status of the last submission.

You can use git reset HEAD 1.txt and then execute git checkout-- 1.txt

Git reflog / / View all historical versions

Delete a file

Echo-e "111111111\ n2222222222" > 2.txt

Git rm 2.txt

Git commit-m "rm 2.txt"

Establish a remote warehouse

First, register an account in https://github.com, create your own git, click repositories in the upper right corner (create a warehouse), and then click new.

Custom name, for example, call studygit and select public point create repository.

Add key: click on your avatar in the upper right corner, select settings, and select SSH and GPG keys on the left

Linux generation key: ssh-keygen

Click New SSH key on the left, and paste the contents of ~ / .ssh/id_rsa.pub (public key) on the linux machine here.

Create an apelearn directory under the server / tmp/ directory: mkdir / tmp/apelearn go to the directory and execute the prompts given by the official website step by step

The step of pushing the local warehouse to the remote warehouse git remote add origin git@github.com:aminglinux/studygit.git / / is to create a new warehouse studygit remotely with the same name as the local one.

Git push-u origin master / / then push the local studygit repository to the remote studygit

Error report:

Solution: yum update-y nss curl libcurl

Success

The next time you push, you can git push directly.

At this point, you can create a file on the server

Vim 1.txt # # write something into it

Git add 1.txt

Git commit-m "1.txt"

Git push # # upload to remote Library

Refresh the page and you will have it.

Clone remote warehouse

Go to any directory randomly: cd / home

Find the code you want to clone from the github website

Copy Link

Copy to the server:

Git clone https://github.com/aminglinux/lanmp.git

It prompts that a repository will be initialized under the current directory and a .git directory will be created, as follows

Initialized empty Git repository in / home/lanmp/.

After git/ is complete, ls can see a directory of lanmp

Cd lanmp

Vi lanmp.sh edits the file and then submits it

Git add lanmp.sh

Git commit-m "sdlfasdf"

And then push it to the remote server

Git push

If there is any change, use git pull to pull down the updated one.

Branch

Git branch / / View branch * number indicates the current branch

Git branch awei / / create a branch

Git checkout awei / / switched to the aming branch

If you look at it with git branch, you will see that there are two branches, master and aming, and there will be an one in front of the currently used branch * under the aming branch, edit 2.txt and submit to the new branch

Echo "askdfjlksadjflk" > 2.txt

Git add 2.txt

Git commit-m "laksjdflksjdklfj"

Switch back to the master branch

Git checkout master / / at this time cat 2.txt found that the content had not changed, indicating that branches and branches are separated from each other.

Merging of branches

Git checkout master / / switch to the target branch before merging the branch

Git merge aming / / merged the aming branch into master

If both the master branch and the aming branch have edited the 2.txt, a conflict will be prompted when the merge occurs, and the conflict needs to be resolved before the merge can proceed.

The way to resolve the conflict is to edit the 2.txt under the master branch and change it to the content of 2.txt in the aming branch. Then submit the 2.txt and merge the aming branch.

But there is a problem, what if the master branch changes what we want? You can edit the 2.txt content, change it to what you want, and then submit. Switch to the aming branch, then merge the master branch into the aming branch (merge backwards). The principle of merging branches is to merge the newest branches into the old ones. In other words, the name of the branch followed by merge must be the latest branch.

Git branch-d aming / / Delete branches

If the branches are not merged, they will be prompted before deletion, then do not merge and force deletion.

Git branch-D aming # # Force deletion

Principles for using branches

For the application of branches, it is recommended that we follow the following principles:

Master branch is very important, online release code with this branch, usually we do not develop code on this branch.

Create a dev branch dedicated to development, and merge the dev branch into master only before it is published online

Developers should branch into personal branches on the basis of dev, develop code in personal branches (on their own pc), and then merge them into dev branches

The command for dev branches to merge bob branches is:

Git checkout dev / / switch to the dev branch first, then

Git merge bob

Remote branch

A new branch created locally will not be visible to others if it is not pushed remotely

Look at the remote branch: git ls-remote origin, you can see all the branches

For git push branches, there are two cases.

When the local branch is consistent with the remote branch

Git push will push changes from all local branches to the remote. If you want to push only one branch, use: git push origin branch-name

When there are more local branches than remote branches, the default git push only pushes the same local and remote branches. When you want to push the extra local branches to the remote, use git push origin branch-name. If the push fails, use git pull to grab the remote new submission first.

When git clone, only master branches are cloned by default. If you want to clone all branches, you need to create them manually and create branches corresponding to remote branches locally.

Using git checkout-b branch-name origin/branch-name, the names of the local and remote branches should be the same # # branch-name is the name of your remote branch. Write whatever the remote branch is called.

For example: dev branch

Label management

Tags are similar to the snapshot function in that you can label a version library to record the status of a time library. You can also return to this state at any time.

Git checkout master is first cut to the master branch

Git tag v1.0 give master a label v1.0

Git show v1.0 View tag Information

Git tag can view all the tags

Tag is tagged for commit, so you can hit tag for historical commit.

Git log-- pretty=oneline-- abbrev-commit / / check the historical commit first

Git tag v0.9 46d3c1a / / label historical commit

Git tag-a v0.8-m "tag just v1.1 and so on" 5aacaf4 / / can describe the tag

Git tag-d v0.8 / / remove tags

Remote label View

Git push origin v1.0 / / push the specified tag to the remote

Wait until you push it.

Git push-- tag origin / / push all tags

If a tag is deleted locally and you want to delete it remotely, you need to do this:

Git tag v1.0-d / / Delete local tags

Git push origin: refs/tags/v1.0 / / Delete remote tags

Git alias

Isn't the git commit command a little long? Using aliases can improve our work efficiency.

Alias format: git config-- global alias. Alias initial name

For example, commit alias ci:

Git config-global alias.ci commit

As shown in the picture

Git config-global alias.co checkout

Git config-global alias.br branch

View git aliases using commands

Git config-- list | grep alias

Another way is to add it directly to the configuration file: / root/.gitconfig

Tips for querying log: execute directly on the command line

Git config-global alias.lg "log-- color-- graph-- pretty=format:'%Cred%h%Creset -% C (yellow)% d%Creset% s% Cgreen (% cr)% C (bold blue)% Creset'-- abbrev-commit"

After the execution, you can execute the git lg.

Cancel alias

Git config-global-unset alias.br

Set up git server

After all, github is public, and private warehouses have to be bought. So we can find a way to build a private one that is only used by our own company. Gitlab is a good choice. Before I introduce it, let's talk about the command line git server.

To find a server, first install git:yum install-y git

Add git users and set shell to / usr/bin/git-shell in order to prevent git users from logging in remotely

Useradd-s / usr/bin/git-shell git

Enter the home directory: cd / home/git

Create an authorized_keys file and change the owner, group, and permissions to store the public key on the client machine

1.mkdir .ssh

2.touch .ssh / authorized_keys

3.chown-R git.git .ssh

4.chmod 600 .ssh / authorized_keys

The purpose of the above operation is to allow another machine to communicate through the key

Put the public key on another machine into the local (server) configuration file

/ home/git/.ssh/authorized_keys

Give it a try and link it with another: ssh git@192.168.182.133

Set a directory to store the git warehouse, such as / data/gitroot

Mkdir / data/gitroot

Cd / data/gitroot

Git init-- bare sample.git / / create a naked warehouse

Ps: the naked warehouse does not have a workspace, because the Git repository on the server is purely for sharing, so users are not allowed to log in directly to the server to change the workspace, and the Git warehouse on the server usually ends with .git.

Chown-R git.git sample.git # # Settings belong to the master group

The above operations are done on the git server. Usually, the git server does not require developers to log in to modify the code. It only acts as a server, just like github, and usually operations are done on our own pc.

First, put the public key on the client side into the git server / home/git/.ssh/authorized_keys file.

Clone a remote repository on the client (self-pc)

Git clone git@192.168.182.133:/data/gitroot/sample.git

At this point, you can generate a sample directory under the current directory, and this is the remote repository we cloned. When you go inside, you can develop some code, and then push it remotely.

Experiment:

[root@localhost ~] # cd sample/ [root@localhost sample] # ls [root@localhost sample] # cp / etc/init.d/mysqld. # # randomly copy a file to [root@localhost sample] # lsmysqld [root@localhost sample] # git add. # # add to the warehouse [root@localhost sample] # git ci-m "add new file" submission (ci is an alias we set for commit) [master (root submission) 028b4a9] add new file Committer: root your name and email address are automatically set based on login name and host name. Please check whether they are correct or not. You can explicitly set it with the following command to avoid the recurrence of this prompt: git config-- global user.name "Your Name" git config-- after the global user.email you@example.com is set You can use the following command to correct the user identity used in this submission: git commit-- amend-- reset-author 1 file changed, 380 insertions (+) create mode 100755 mysqld [root@localhost sample] # git push # # pushed to the remote warehouse, an error will be reported here because the first push does not know which branch you want to push, and the solution specifies that the branch warning: push.default is not set Its default value will be changed from 'matching'' to 'simple'' in Git 2.0. To no longer display this information and maintain the current usage habits after its default value is changed, make the following settings: git config-- global push.default matching if you want to stop displaying this information and adopt the new usage habits from now on, set: git config-- global push.default simple see 'git help config' and look for' push.default' for more information. (the 'simple' mode was introduced by Git version 1.7.11. If you sometimes want to use an older version of Git, to maintain compatibility, use 'current' instead of' simple' mode) No refs in common and none specified Doing nothing.Perhaps you should specify a branch such as' master'.fatal: The remote end hung up unexpectedlyerror: unable to push some references to 'git@192.168.182.133:/data/gitroot/sample.git' [root@localhost sample] # git push origin master # # specified branch Successful push Counting objects: 3, done.Delta compression using up to 2 threads.Compressing objects: 100% (2max 2), done.Writing objects: 100% (3max 3), 3.85 KiB | 0 bytes/s, done.Total 3 (delta 0) Reused 0 (delta 0) To git@192.168.182.133:/data/gitroot/sample.git * [new branch] master-> master [root@localhost sample] # [root@localhost tmp] # git clone git@192.168.182.133:/data/gitroot/sample.git # # Clone the server library Cloning to tmp is cloning to 'sample'...remote: Counting objects: 3, done.remote: Compressing objects: 100% (2delta 2), done.remote: Total 3 (delta 0), reused 0 (delta 0) receiver: 100% (3 delta 3) Done. [root@localhost tmp] # lsapelearn mysql.sock sample [root@localhost tmp] # ls sample/mysqld [root@localhost tmp] # cd sample/ [root@localhost sample] # lsmysqld [root@localhost sample] # mkdir 222.txt then create a new file in the cloned library Write something [root@localhost sample] # vim 222.txt [root@localhost sample] # git add 222.txt [root@localhost sample] # git commit-m "ch 222.txt" [master 44076d8] ch 222.txt Committer: root your name and email address are automatically set based on login and hostname. Please check whether they are correct or not. You can explicitly set it with the following command to avoid the recurrence of this prompt: git config-- global user.name "Your Name" git config-- after the global user.email you@example.com is set You can use the following command to correct the user identity used in this submission: git commit-- amend-- reset-author 1 file changed, 1 insertion (+) create mode 100644 222.txt [root@localhost sample] # git push # # and push it to the remote server warning: push.default is not set, its default value will be changed from 'matching' to' simple' at Git 2.0. To no longer display this information and maintain the current usage habits after its default value is changed, make the following settings: git config-- global push.default matching if you want to stop displaying this information and adopt the new usage habits from now on, set: git config-- global push.default simple see 'git help config' and look for' push.default' for more information. (the 'simple' mode was introduced by Git version 1.7.11. If you sometimes want to use an older version of Git, to maintain compatibility Please use 'current' instead of' simple' mode) Counting objects: 4, done.Delta compression using up to 2 threads.Compressing objects: 100% (2 bytes 2), done.Writing objects: 100% (3 delta 3), 280 bytes | 0 bytes/s, done.Total 3 (delta 0) Reused 0 (delta 0) To git@192.168.182.133:/data/gitroot/sample.git 028b4a9..44076d8 master-> master [root@localhost sample] # pwd/tmp/sample [root@localhost sample] # cd / root/sample/ enter the directory of the initial clone library [root@localhost sample] # lsmysqld [root@localhost sample] # git pull # # pull the file remote: Counting objects: 4, done.remote: Compressing objects: 100% (2max 2), done.remote: Total 3 (delta 0) Reused 0 (delta 0) Unpacking objects: 100% (3amp 3), done. From 192.168.182.133:/data/gitroot/sample 028b4a9..44076d8 master-> origin/master update 028b4a9..44076d8Fast-forward 222.txt | 1 + 1 file changed, 1 insertion (+) create mode 100644 222.txt [root@localhost sample] # cat 222.txt found that it is a newly uploaded 222.txt file, which is also a way to akakda [root@localhost sample] # ls222.txt mysqld [root@localhost sample] #

Use gitlab

Gitlab official website https://about.gitlab.com/gitlab-com/

Official installation documentation https://about.gitlab.com/installation/?version=ce#centos-7 (ce/ee)

Server memory is required to be no less than 2g

Vim / etc/yum.repos.d/gitlab.repo// adds the following

[gitlab-ce]

Name=Gitlab CE Repository

Baseurl= https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/

Gpgcheck=0

Enabled=1

Yum install-y gitlab-ce

Compile and install: gitlab-ctl reconfigure

After the installation is successful, he will start your service automatically.

Netstat-lnpt / / View listening port

Gitlab-ctl stop/restart/start/status # # shutdown / restart / startup / status

The browser accesses gitlab and type ip.

The default administrator, root, has no password, which allows us to define a password

Log in

Gitlab Common Command https://www.cnyunwei.cc/archives/1204

Gitlab backup gitlab-rake gitlab:backup:create

The backup directory is in / var/opt/gitlab/backups

Gitlab recovers data

Stop the service gitlab-ctl stop unicorn / gitlab-ctl stop sidekiq first

Gitlab-rake gitlab:backup:restore BACKUP=xxxxx (here is a number, that is, the prefix of the backup file)

Restart the service gitlab-ctl start

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report