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

Gitlab usage and Branch Management (3)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

(1) configure SSH to Gitlab account

1. Use ssh-keygen to generate key file. Ssh/id_rsa.pub

[root@zabbix-proxy0496 ~] # ssh-keygen Generating public/private rsa key pair.Enter file in which to save the key (/ root/.ssh/id_rsa): 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:SHA256:3DpddsSwRtOfMSDE8NSancZpL9sP7LPKFZQmjc2BWxc root@zabbix-proxy0496The key's randomart image is:+--- [RSA 2048]-- -+ |. + + = + oE. | | ooo@o=. | | .Xo% o + | |. . +.%. | | S. = + | | o + o | | o. B | |. . + .o | | o.ooo | +-[SHA256]-+

2. View the configuration ciphertext of the public key

[root@zabbix-proxy0496] # cat ~ / .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJLYoootIWqpvrvuCpdCzSQGFHt/AYrXo5eYiqU6f2x8e55EjlOTMchykdBdZH0E38T7E/0GVD5J4Juo0F4TKXQAS0Vcg3MvDdaMyJRUBliN+CP8PjiTcKmLBXXnFTyr2d7XSLrkOq7EMf5PXpvl/SK+ildMC0YKNm2bDcg6hTRdWMoSC9dqUY/xNXmCxAn020dolfyyMb8NBmQCZOjZUlyfZt0KFnyMU3I8Fa5ex6Ow8ymGcTRnc/oXrOhclVU7e7tZ+zpe0EibKcsd7vDvW/fXIIkU7DXEMxn5mldf8rq81Zij0YgmebFpHI34dQ4UK1ey7PhIR73tCktUdsUmVX root@zabbix-proxy0496

3. Add ssh-key login to gitlab

(2) Common operations

1. Clone the relevant code

[root@zabbix-proxy0496 gitlab] # git clone git@192.168.4.97:lqb/yw.gitCloning into 'yw'...The authenticity of host' 192.168.4.97 (192.168.4.97) 'can't be established.ECDSA key fingerprint is SHA256:7OoUZ9xWrE2sHmPq57C3L/DJdhX+zrrYlm58tboarqQ.ECDSA key fingerprint is MD5:fa:38:e5:fc:90:d2:37:47:d4:0f:56:94:2e:8b:44:50.Are you sure you want to continue connecting (yes/no)? YesWarning: Permanently added '192.168.4.97' (ECDSA) to the list of known hosts.remote: Enumerating objects: 25, done.remote: Counting objects: 100% (25done.remote 25), done.remote: Compressing objects: 100% (20done.remote 20), done.remote: Total 25 (delta 6), reused 0 (delta 0) Receiving objects: 100% (25x25), 67.95 KiB | 0 bytes/s, done.Resolving deltas: 100% (6x6), done. [root@zabbix-proxy0496 gitlab] # lsyw

2. Enter the corresponding warehouse to check the git status.

[root@zabbix-proxy0496 gitlab] # cd yw/ [root@zabbix-proxy0496 yw] # git status# On branch masternothing to commit, working directory clean [root@zabbix-proxy0496 yw] # ls1.png CONTRIBUTING.md Dockerfile lqb README.md test.sh

3. Create the corresponding code to add to the temporary storage area and upload it to the gitlab server

[root@zabbix-proxy0496 yw] # echo "this is first" > index.html [root@zabbix-proxy0496 yw] # cat index.html this is first [root@zabbix-proxy0496 yw] # git add index.html [root@zabbix-proxy0496 yw] # git commit-m'first commit' [master 7d6a20e] first commit 1 file changed, 1 insertion (+), 1 deletion (-) [root@zabbix-proxy0496 yw] # git push-u origin masterCounting objects: 7, done.Delta compression using up to 4 threads.Compressing objects: 100% (4git commit 4) Done.Writing objects: 100% (6 bytes), 519 bytes | 0 bytes/s, done.Total 6 (delta 2), reused 0 (delta 0) To git@192.168.4.97:lqb/yw.git 4497bc1..7d6a20e master-> masterBranch master set up to track remote branch master from origin.

4. Related commonly used commands

[root@zabbix-proxy0496 yw] # git log # View the history submission history [root@zabbix-proxy0496 yw] # git reflog # View the future history update point [root@zabbix-proxy0496 yw] # git reset-- hard HEAD # restore the last submitted version Last submitted version HEAD#git deletes data 1, git rm-- cached database # removes files from the tracking list of git staging areas and does not delete data files in the current working directory-> only delete cache 2, git rm-f database 4 # removes file data from both the git staging area and the working directory-> permanent deletion # git renamed data 3, Git mv README NOTICE # before README modification / after NOTICE modification Finally, submit the git repository 2 Note: you can also change the name → to delete the file snapshot of the git repository, git rm'* .txt '→, add the new file to the → submission git warehouse remarks: git rm-f filename # Delete the files in the work area and staging area (use-- cached to keep the file Or-f to force removal) ​ git diff file # compare local vs staging area git diff-- cached file # staging area vs local version library git log-- oneline # one-line display-- decorate # specific operation ​ git log-p # display details git log-displaying 1 commit is equivalent to doing a snapshot from Restore staging area to local workspace git checkout-- file # undo workspace changes from version library restore [overwrite] to staging area (staging area error add delivery) git reset HEAD file rollback from version library to version [a commit version] git reset-hard f34j34 fallback The git log log after the fallback point cannot be seen by git reflog to view the logs of all commit

5. Label use (usually used after commit)

[root@zabbix-proxy0496 yw] # git tag v2.0 # tag current content [root@zabbix-proxy0496 yw] # git show v2.0 # View details of the current version v2.0 tag [root@zabbix-proxy0496 yw] # git tag v2.1-m "version 2.1 release is test" # Mark the current version (latest) Used for marking after commit submission (- a specifies the label signature -m for description) [root@zabbix-proxy0496 yw] # git tag # View all current tags v1.0v2.0v2.1 [root@zabbix-proxy0496 yw] # git tag-d v2.0 # Delete the tag v2.0Deleted tag 'v2.0' (was 1c2bec9) [root@zabbix-proxy0496 yw] # git reset-- hard v2.2HEAD is now at 02318ea this is second [root@zabbix-proxy0496 yw] # git Reset-- hard 02318ea # Quick rollback of HEAD is now at 02318ea this is second

Workspace: workspace

Index/Stage/Cached: staging area

Repository: local warehouse

Remote: remote warehouse

The Git command is used to switch file changes to a different space to record.

(3) the concept of branch

A branch of Git is essentially just a variable pointer to a commit object. It is essentially different from SvN on this point. The branch of SVN is actually a directory.

The default branch name for Git is master. After multiple commit operations, you already have a master branch that points to the last commit object. It automatically moves forward during each commit operation.

The git branch is shown below

Common commands are as follows:

Git branch # View branches git checkout dev # switch branches git merge dev # merge branches conflict if the same file is modified, the conflicting files need to be modified in master, add submitted, commit-> merge completed git brach-d dev delete branches

In the actual project development, try to ensure the stability of the master branch, only for the release of new versions, usually do not directly modify the data files. The developers all make modifications in the dev branch, that is, everyone creates their own personal branch from the dev branch, merges it into the dev branch after development, and finally merges it into the master branch.

1. Create and switch branches

[root@zabbix-proxy0496 yw] # git branch dev # create Branch [root@zabbix-proxy0496 yw] # git branch # View Branch current branch has * number dev* master [root@zabbix-proxy0496 yw] # git checkout dev # switch branch Switched to branch 'dev' [root@zabbix-proxy0496 yw] # git checkout index.html # one button restore Directly overwrite the current file from the git repository [dangerous] [root@zabbix-proxy0496 yw] # git branch* dev master

2. Merge branches

[root@zabbix-proxy0496 yw] # git checkout master # switch branches Switched to branch 'master' [root@zabbix-proxy0496 yw] # git merge dev # dev branches are merged into masterMerge made by the' recursive' strategy. 1.log | 1 + 1 file changed 1 insertion (+) create mode 100644 1.log [root@zabbix-proxy0496 yw] # git branch dev* master [root@zabbix-proxy0496 yw] # tree. ├── 1.log ├── 1.png ├── CONTRIBUTING.md ├── Dockerfile index.html ├── lqb README.md └── test.sh [root@zabbix-proxy0496 yw] # git branch-d dev # Delete dev branch Deleted branch dev (was a9b4292). [root@zabbix-proxy0496 yw] # git branch* master

(IV) Github

Github, as its name implies, is the hosting service for a Git version library, the largest software repository in the world, with millions of developers and users, and the best way to develop software and find resources. Github can not only host a variety of Git version repositories, but also have a more beautiful look.

With the Web interface, your code files can be cloned by anyone, making it easier for developers to contribute code to open source items. Of course, they can also pay for private libraries. Such cost-effective private libraries really help many teams and enterprises.

1. Registered users

2. Configure ssh-key

3. Create a project

4. Clone the project locally

5. Push and modify to remote

Echo "# git" > > README.mdgit initgit add README.mdgit commit-m "first commit" git remote add origin git@github.com:lewen/git.gitgit push-u origin mastergit remote add origin git@github.com:lewen/git.gitgit push-u origin masterssh-keygen-t rsa adds a public key to a public key and binds the github only once to pull down the remote. After merging, pushgit fetch updates the remote to the local git merge origin/master and merges the remote to the local master first, then merges it. Then push # commonly used command 1 add # to add file contents to index 2 branch # list, Create or delete branch 3 checkout # check out a branch or path to workspace 4 clone # Clone a version library to a new directory 5 commit # record changes to version library 6 init # create an empty Git version library or reinitialize an existing version library 7 log # display submission log 8 merge # merge two or more development history 9 mv # move or rename a file, Directory or symbolic link 10 pull # get and merge another version library or a local branch 11 push # update remote references and related objects 12 rm # remove files from workspaces and indexes 13 show # display various types of objects 14 status # display workspace status 15 tag # create, list, delete or verify an GPG signed tag object

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