gitlab基礎命令之代碼回滾


#:gitlab狀態

root@ubuntu:~# gitlab-ctl status
run: alertmanager: (pid 13305) 215965s; run: log: (pid 13081) 215991s
run: gitaly: (pid 13180) 215968s; run: log: (pid 12160) 216098s
run: gitlab-monitor: (pid 13241) 215968s; run: log: (pid 12828) 216009s
run: gitlab-workhorse: (pid 13215) 215968s; run: log: (pid 12681) 216032s
run: logrotate: (pid 75944) 144715s; run: log: (pid 12738) 216021s
run: nginx: (pid 12690) 216028s; run: log: (pid 12706) 216027s
run: node-exporter: (pid 13228) 215968s; run: log: (pid 12793) 216013s
run: postgres-exporter: (pid 13320) 215965s; run: log: (pid 13141) 215983s
run: postgresql: (pid 12311) 216093s; run: log: (pid 12408) 216090s
run: prometheus: (pid 13271) 215967s; run: log: (pid 12955) 215997s
run: redis: (pid 12080) 216105s; run: log: (pid 12112) 216102s
run: redis-exporter: (pid 13258) 215967s; run: log: (pid 12911) 216002s
run: sidekiq: (pid 12624) 216040s; run: log: (pid 12644) 216039s
run: unicorn: (pid 12572) 216046s; run: log: (pid 12607) 216045s

#:初始化環境(每次更改完配置都要執行此命令)

root@ubuntu:~# gitlab-ctl reconfigure

#:列出當前的所有組件

root@ubuntu:~# gitlab-ctl service-list
 
#:重啟gitlab(如果想單獨重啟某個服務,后面跟服務名)

root@ubuntu:~# gitlab-ctl restart 

#:進入到postsql數據庫

root@ubuntu:~# gitlab-rails dbconsole

psql (9.6.11)
Type "help" for help.

gitlabhq_production=> 
gitlabhq_production=> \db
         List of tablespaces
    Name    |    Owner    | Location 
------------+-------------+----------
 pg_default | gitlab-psql | 
 pg_global  | gitlab-psql | 
(2 rows)

gitlabhq_production=> \help


#:查看某個單獨服務的日志

root@ubuntu:~# gitlab-ctl tail nginx

#:克隆項目

root@ubuntu:/opt# git clone http://192.168.6.101/linux37/web1.git

 

#:Git命令使用

#:先在遠程倉庫克隆下來一段代碼

root@ubuntu:/opt# git clone http://192.168.6.101/linux37/web1.git
Cloning into 'web1'...
Username for 'http://192.168.6.101': xiaoming
Password for 'http://xiaoming@192.168.6.101': 
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
root@ubuntu:/opt# ls
gitlab  web1

#:對代碼進行修改

root@ubuntu:/opt# vim web1/index.html
this is test page
this is test page v2
root@ubuntu:/opt# cd web1/

#:先放到暫存區

root@ubuntu:/opt/web1# git add index.html

#:在提交到本地存儲

root@ubuntu:/opt/web1# git commit -m "v2"

#:在提交到倉庫
root@ubuntu:/opt/web1# git push



#:也可以提交一個目錄
#:先創建一個目錄
root@ubuntu:/opt/web1# mkdir app
#:在此目錄下寫點代碼
root@ubuntu:/opt/web1# vim app/index.html
this is directory v1
#:放到暫存區
root@ubuntu:/opt/web1# git add ./*
#:提交到本地倉庫
root@ubuntu:/opt/web1# git commit -m "v1"
#:提交到遠程倉庫
root@ubuntu:/opt/web1# git push


#:當剛提交到暫存區的時候可以用Git status查看到
root@ubuntu:/opt/web1# git add index.html 
root@ubuntu:/opt/web1# git staus
git: 'staus' is not a git command. See 'git --help'.

The most similar command is
    status
root@ubuntu:/opt/web1# git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   index.html


#:查看相關日志
root@ubuntu:/opt/web1# git log
commit 416ab98610aaa8939f48ee43be46598d75efa7ab (HEAD -> master, origin/master, origin/HEAD)
Author: xiaoming <316428921@qq.com>
Date:   Sun Sep 29 10:46:42 2019 +0800

    v3  #:這個就是commit注釋的內容

commit 42785a48c2f235df7276ed15a2bfd14a46e1e023  #:此處是tag號
Author: xiaoming <316428921@qq.com>
Date:   Sun Sep 29 10:40:23 2019 +0800

    v1



#:代碼回滾(一個 ^ 就是一個版本)注:回滾的時候只能在未提交到倉庫的時候回滾

root@ubuntu:/opt/web1# git reset --hard HEAD^

#:查詢tag號
root@ubuntu:/opt/web1# git reflog
416ab98 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: pull: Fast-forward
3d91a05 HEAD@{1}: reset: moving to HEAD^

root@ubuntu:/opt/web1# git reset 53082b0  #:回滾的時候可以指定tag號回滾



#:查看所有分支

root@ubuntu:/opt/web1# git branch
* master
 
#:指定分支克隆
root@ubuntu:/opt# git clone -b develop http://192.168.6.101/linux37/web1.git

#:切換分支

root@ubuntu:/opt/web1# git checkout master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to a new branch 'master'
root@ubuntu:/opt/web1# git checkout
Your branch is up to date with 'origin/master'

 


免責聲明!

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



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