主頁 > 後端開發 > 學習git這一篇就夠了!!!

學習git這一篇就夠了!!!

2020-10-14 16:55:11 後端開發

git命令操作

本地庫操作

初始化本地倉庫

  • 初始化命令

    git init

    $ work % cd workspace $ workspace % mkdir WebService //創建檔案夾 $ workspace % git init //初始化 Initialized empty Git repository in /Users/jack/work/workspace/.git/ $ workspace %

  • 初始化后的效果

    會在初始化后的目錄中生成一個.git隱藏檔案夾

    $ workspace % cd .git $ .git % ls HEAD branches config description hooks info objects refs $ .git % ls -l total 24 -rw-r--r-- 1 jack staff 23 Sep 25 22:16 HEAD drwxr-xr-x 2 jack staff 64 Sep 25 22:16 branches -rw-r--r-- 1 jack staff 137 Sep 25 22:16 config -rw-r--r-- 1 jack staff 73 Sep 25 22:16 description drwxr-xr-x 13 jack staff 416 Sep 25 22:16 hooks drwxr-xr-x 3 jack staff 96 Sep 25 22:16 info drwxr-xr-x 4 jack staff 128 Sep 25 22:16 objects drwxr-xr-x 4 jack staff 128 Sep 25 22:16 refs $ .git %

注意:.git目錄中的檔案不要洗掉也不要修改,否則git不能正常作業,

設定簽名

  • 形式

    用戶名:XXX

    Email地址:[email protected]

  • 作用

    只是為了區分成員身份,不會給郵件地址發送郵件,而且郵件地址可以是不存在地址,

  • 注意

    這里的簽名和遠程倉庫的郵件地址密碼沒有任何關系

  • 命令

    1. 專案級別/倉庫級別

      僅在當前本地倉庫有效

      git config user.name

      **用戶名**

      git config user.email

      **郵箱地址**

      $ WebService % git config user.name njzy
      $ WebService % git config user.email [email protected] $ WebService %

    2. 系統用戶級別

      登錄當前系統的用戶范圍

      git config --global user.name

      **用戶名**

      git config --global user.email

      **郵箱地址**

      $ WebService % git config --global user.name njzy_global $ WebService % git config --global user.email [email protected] $ WebService %

  • 簽名保存位置

    1.專案級別

    當前專案下的.git檔案夾下的config檔案中,

    查看命令:cat .git/config

    $ WebService % cat .git/config //查看當前專案的簽名資訊                            
    [core]
      repositoryformatversion = 0
      filemode = true
      bare = false
      logallrefupdates = true
      ignorecase = true
      precomposeunicode = true
    [user]
      name = njzy //被設定的專案用戶名
      email = [email protected] //被設定的專案郵件地址
    $ WebService %
    復制代碼

    2.系統用戶級別

    當前用戶檔案夾下的.gitconfig檔案中,

    查看命令:cat .gitconfig

    $ ~ % cd ~ //切換到當前用戶根目錄
    $ ~ % pwd  //查看當前位置
    /Users/jack
    $ ~ % cat .gitconfig //查看全域簽名資訊
    [user]
      name = njzy_global //被設定的全域用戶名
      email = [email protected] //被設定的全域郵件地址
    $ ~ %
    復制代碼
  • 專案級別和系統用戶級別的簽名的優先(就近原則)

    1.> 兩個都設定情況下

    專案級別優先于系統用戶級別

    2.> 只設定系統用戶級別簽名

    以系統用戶級簽名別為準

    3.> 只設定專案級別

    以專案級別為準

    4.> 兩個都沒有設定的話不允許,

查看git狀態

  • 作用
    確認git的暫存區,本地倉庫的情況,
  • 命令
    git status

添加操作

  • 目的

    把內容從作業區添加到暫存區,也叫追蹤,

  • 命令

    1.添加單個檔案

    git add 檔案名

    2.添加多個檔案

    1.> git add 檔案名1 檔案名2 檔案名3 ....

    2.> git add -A

    3.> git add .

    詳細參考git幫助檔案

    usage: git add [<options>] [--] <pathspec>...
    
        -n, --dry-run         dry run
        -v, --verbose         be verbose
    
        -i, --interactive     interactive picking
        -p, --patch           select hunks interactively
        -e, --edit            edit current diff and apply
        -f, --force           allow adding otherwise ignored files
        -u, --update          update tracked files //更新追蹤的檔案
        --renormalize         renormalize EOL of tracked files (implies -u)
        -N, --intent-to-add   record only the fact that the path will be added later
        -A, --all             add changes from all tracked and untracked files //添加所有被追蹤檔案的更新,和沒有被追蹤的檔案
        --ignore-removal      ignore paths removed in the working tree (same as --no-all) //忽略作業區被洗掉的檔案
        --refresh             don't add, only refresh the index 
        --ignore-errors       just skip files which cannot be added because of errors //忽略由于檔案的錯誤不能被追蹤
        --ignore-missing      check if - even missing - files are ignored in dry run
        --chmod (+|-)x        override the executable bit of the listed files
    復制代碼
  • 使用例

    為了清除git各個階段的狀態,在進行添加操作之前先查看一下git的狀態,

    (下面例子是從作業區檔案的創建到追加暫存區的程序)

    1.查看作業區被初始化后的狀態

    $ WebService % git status
    On branch master
    
    No commits yet //本地倉庫沒有可提交的東西
    
    nothing to commit (create/copy files and use "git add" to track) //暫存區沒有可以提交的東西
    $ WebService %
    復制代碼

    2.創建檔案testGIt.txt檔案

    $ WebService % vim testGit.txt
    $ WebService % cat testGit.txt
    //查看檔案內容
    hello !
    this is my first git test file !
    $ WebService %
    復制代碼

    3.查看檔案創建完后git狀態

    $ WebService % git status
    On branch master
    
    No commits yet //本地倉庫沒有樂意提交的東西,
    
    Untracked files: //沒有追加跟蹤的檔案
      (use "git add <file>..." to include in what will be committed) //使用git add <file> 命令可以追加檔案到暫存區
        testGit.txt //剛才新創建的檔案,此時檔案名字體為紅色
    
    nothing added to commit but untracked files present (use "git add" to track) //使用git add命令
    $ WebService %
    復制代碼

    4.將檔案添加到暫存區并查看狀態

    $ WebService % git add testGit.txt
    $ WebService % git status
    On branch master
    
    No commits yet
    
    Changes to be committed:
      (use "git rm --cached <file>..." to unstage) //已經把檔案放到暫存區,如果想清除暫存區,可以使用git rm --cached 檔案名來擦除暫存區 testGit.txt
        new file:   testGit.txt //此時檔案為綠色
    
    $ WebService %
    復制代碼

提交操作

  • 目的

    將檔案從暫存區提交到本地倉庫

  • 命令

    1.提交單個檔案

    git commit -m "提交時注釋資訊" 檔案名

    2.提交復數個檔案

    git comit -a -m "提交時注釋資訊"

    更多詳細可以參考git幫助檔案

    usage: git commit [<options>] [--] <pathspec>...
    
        -q, --quiet           suppress summary after successful commit
        -v, --verbose         show diff in commit message template
    
    Commit message options
        -F, --file <file>     read message from file
        --author <author>     override author for commit
        --date <date>         override date for commit
        -m, --message <message>
                              commit message
        -c, --reedit-message <commit>
                              reuse and edit message from specified commit
        -C, --reuse-message <commit>
                              reuse message from specified commit
        --fixup <commit>      use autosquash formatted message to fixup specified commit
        --squash <commit>     use autosquash formatted message to squash specified commit
        --reset-author        the commit is authored by me now (used with -C/-c/--amend)
        -s, --signoff         add Signed-off-by:
        -t, --template <file>
                              use specified template file
        -e, --edit            force edit of commit
        --cleanup <mode>      how to strip spaces and #comments from message
        --status              include status in commit message template
        -S, --gpg-sign[=<key-id>]
                              GPG sign commit
    
    Commit contents options
        -a, --all             commit all changed files
        -i, --include         add specified files to index for commit
        --interactive         interactively add files
        -p, --patch           interactively add changes
        -o, --only            commit only specified files
        -n, --no-verify       bypass pre-commit and commit-msg hooks
        --dry-run             show what would be committed
        --short               show status concisely
        --branch              show branch information
        --ahead-behind        compute full ahead/behind values
        --porcelain           machine-readable output
        --long                show status in long format (default)
        -z, --null            terminate entries with NUL
        --amend               amend previous commit
        --no-post-rewrite     bypass post-rewrite hook
        -u, --untracked-files[=<mode>]
                              show untracked files, optional modes: all, normal, no. (Default: all)
    復制代碼
  • 使用例

    提交檔案到本地倉庫并查看git狀態

    $ WebService % git commit -m "first commit:new file testGit.txt" testGit.txt
    [master (root-commit) c970a17] first commit:new file testGit.txt //first commit:new file testGit.txt 是提交時候的注釋資訊
     1 file changed, 2 insertions(+) //改變了一個檔案,追加了兩行資訊,
     create mode 100644 testGit.txt
    $ WebService % git status            
    On branch master
    nothing to commit, working tree clean //暫存區沒有可以提交的東西
    $ WebService %
    復制代碼

擦除暫存區操作

  • 目的

    擦除暫存區的內容

  • 命令

    git rm --cached 檔案名

    $ WebService % git rm --cached testGit.txt
    rm 'testGit.txt'
    $ WebService % git status                 
    On branch master
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
        testGit.txt //沒有被追蹤的檔案
    
    nothing added to commit but untracked files present (use "git add" to track)
    $ WebService %
    復制代碼

查看歷史版本資訊

  • 目的

    查看提交版本的歷史資訊

  • 命令

    1.git log

    顯示完整資訊,包含提交的版本號,提交用戶,提交日期,提交注釋等資訊,

    2.git log --pretty=oneline

    只包含提交后的完整版本號和提交時的注釋資訊

    3.git log --oneline

    包含提交后的簡略版本號和提交時的注釋資訊

  • 注意

    只能查看已經被提交(commit)的檔案的歷史資訊,

  • 使用例1

    $ WebService % git log
    //第二次被提交的資訊
    commit 148942fd3c0ff3e01e09bf98d883f97a3b0a9c86 (HEAD -> master) //提交版本的hash值
    Author: njzy <[email protected]> //提交用戶資訊
    Date:   Sat Sep 26 15:53:52 2020 +0900 //提交日期
    
        this is my second commit, modify testGit.txt //提交時注釋
    //第一次被提交的資訊
    commit c970a176de13abc4d436e4a08df329046ef193e7
    Author: njzy <[email protected]>
    Date:   Sat Sep 26 12:30:20 2020 +0900
    
        first commit:new file testGit.txt
    $ WebService %
    復制代碼
  • 使用例2

    $ WebService % git log --pretty=oneline
    148942fd3c0ff3e01e09bf98d883f97a3b0a9c86 (HEAD -> master) this is my second commit, modify testGit.txt
    c970a176de13abc4d436e4a08df329046ef193e7 first commit:new file testGit.txt
    $ WebService %
    復制代碼
  • 使用例3

    $ WebService % git log --oneline
    
    148942f (HEAD -> master) this is my second commit, modify testGit.txt
    c970a17 first commit:new file testGit.txt
    $ WebService %
    復制代碼

歷史版本的前進或者回退

查看帶head資訊的日志

  • 目的

    查看帶有指標和hash地址的日志資訊,方便進行版本的前進或者后退,

  • 命令

    git reflog

  • 使用例

    $ WebService % git reflog
    148942f (HEAD -> master) HEAD@{0}: commit: this is my second commit, modify testGit.txt 
    //148942f:簡短的hash地址
    //HEAD@{0}:指標0的位置
    c970a17 HEAD@{1}: commit (initial): first commit:new file testGit.txt
    //HEAD@{1} 指標1的位置
    $ WebService %
    復制代碼

版本的前進或者和回退

基于hash地址的版本指定【推薦】

  • 目的

    對版本進行前進操作或者回退操作

  • 命令

    git reset --hard 指定版本的hash地址

  • 使用例

    從第五個版本跳轉到第三個版本

    $ WebService % git reflog //首先查看各種版本資訊
    d3c9608 (HEAD -> master) HEAD@{0}: commit: this is my fifth updata,updata testGit.txt
    364024e HEAD@{1}: commit: this is my fourth commit,updata testGit.txt
    9dba7c5 HEAD@{2}: commit: this is my third commit,updata testGit.txt
    148942f HEAD@{3}: commit: this is my second commit, modify testGit.txt
    c970a17 HEAD@{4}: commit (initial): first commit:new file testGit.txt
    $ WebService % cat testGit.txt //查看當前版本的檔案內容
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    this is my four updata!
    
    this is my fifth updata!
    $ WebService % git reset --hard 9dba7c5
    //然后根據查看的版本地址資訊,指定到要恢復到的版本,
    HEAD is now at 9dba7c5 this is my third commit,updata testGit.txt
    $ WebService % cat testGit.txt //然后查看回退后的當前版本檔案內容         
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService % git reflog //然后我們再來看一下log資訊
    9dba7c5 (HEAD -> master) HEAD@{0}: reset: moving to 9dba7c5
    d3c9608 HEAD@{1}: commit: this is my fifth updata,updata testGit.txt
    364024e HEAD@{2}: commit: this is my fourth commit,updata testGit.txt
    9dba7c5 (HEAD -> master) HEAD@{3}: commit: this is my third commit,updata testGit.txt
    148942f HEAD@{4}: commit: this is my second commit, modify testGit.txt
    c970a17 HEAD@{5}: commit (initial): first commit:new file testGit.txt
    $ WebService %
    復制代碼

使用^符號(只能進行版本的后退不能前進)

  • 目的

    進行版本的回退

  • 命令

    git reset --hard HEAD^

    (注意:一個^代表倒退一個版本)

  • 使用例

    從第四個版本倒退到一個版本到第三個版本

    $ WebService % git reset --hard HEAD^
    HEAD is now at 9dba7c5 this is my third commit,updata testGit.txt
    $ WebService % cat testGit.txt       
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService %
    復制代碼

    倒退兩個版本

    $ WebService % git reset --hard HEAD^^ 
    HEAD is now at c970a17 first commit:new file testGit.txt
    $ WebService % cat testGit.txt        
    hello !
    this is my first git test file !
    $ WebService %
    復制代碼

使用~符號

  • 目的

    退回指定版本

    (只能倒退,但是可以指定指定退幾步)

  • 命令

    git reset --hard HEAD~要退的步數

  • 使用例

    從當前版本第五版后退兩步到第三個版本

    $ WebService % git reset --hard HEAD~2 
    HEAD is now at 9dba7c5 this is my third commit,updata testGit.txt
    $ WebService % cat testGit.txt         
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService %
    復制代碼

reset三個引數的對比(對比詳細圖文參照文末圖片1,2,3)

--soft引數

  • 說明

    僅在本地倉庫移動HEAD指標

  • 命令

    git reset -soft 指定版本號

  • 使用例

    $ WebService % cat testGit.txt //退回版本之前查看檔案內容
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService % git reset --soft 148942f
    //退回版本操作
    $ WebService % cat testGit.txt //退回版本資訊后查看檔案內容        
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService % git status //查看狀態
    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
        modified:   testGit.txt //查看完后顯示為綠色字體,表示被更改了,為哈如此呢?
        //是由于原來本地倉庫,暫存區,作業區的指標是相同的,而經過soft操作后,本地倉庫的指標發生變化,導致暫存區的指標相對的產生了變化,所以顯示是發生了變化,
    
    $ WebService %
    復制代碼

--mixd引數

  • 說明

    在本地倉庫移動HEAD指標,重置暫存區,

  • 命令

    git reset --mixed 指定版本號

  • 使用例

    $ WebService % cat testGit.txt //跳轉到其他版本之前檔案內容
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService % git reset --mixed d3c9608
    //指定到指定版本
    Unstaged changes after reset:
    M   testGit.txt
    $ WebService % git reflog
    //指定版本后的日志
    d3c9608 (HEAD -> master) HEAD@{0}: reset: moving to d3c9608
    148942f HEAD@{1}: reset: moving to 148942f
    9dba7c5 HEAD@{2}: reset: moving to HEAD~2
    d3c9608 (HEAD -> master) HEAD@{3}: reset: moving to d3c9608
    c970a17 HEAD@{4}: reset: moving to HEAD^^
    9dba7c5 HEAD@{5}: reset: moving to HEAD^
    364024e HEAD@{6}: reset: moving to 364024e
    9dba7c5 HEAD@{7}: reset: moving to 9dba7c5
    d3c9608 (HEAD -> master) HEAD@{8}: commit: this is my fifth updata,updata testGit.txt
    364024e HEAD@{9}: commit: this is my fourth commit,updata testGit.txt
    9dba7c5 HEAD@{10}: commit: this is my third commit,updata testGit.txt
    148942f HEAD@{11}: commit: this is my second commit, modify testGit.txt
    c970a17 HEAD@{12}: commit (initial): first commit:new file testGit.txt
    $ WebService % cat testGit.txt  //查看切換版本后的檔案內容        
    hello !
    this is my first git test file !
    
    this is added 
    
    this is my third updata!
    
    $ WebService % git status
    On branch master
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
        modified:   testGit.txt //此時檔案名是紅色
    
    no changes added to commit (use "git add" and/or "git commit -a")
    $ WebService %
    復制代碼

--hard引數

  • 說明
    在本地倉庫移動HEAD指標
    重置暫存區
    重置作業區
  • 命令
    git reset --hard 指定版本
  • 使用例
    參照上面各種版本前進或者后退的例子,

洗掉檔案并找回

  • 前提

    提交到本地庫后洗掉才能找回

  • 洗掉

    物理洗掉即可

  • 找回版本

    通過跳轉到指定版本命令即可找回洗掉的內容,

  • 使用例

    新建檔案->追加到暫存區->提交到本地倉庫->洗掉檔案->添加到暫存區->提交到本地倉庫

    $ WebService % vim test2.txt //1.創建一個新的測驗檔案
    $ WebService % git add test2.txt //2.添加到暫存區
    $ WebService % git commit -m "add new test2.txt" test2.txt //3.提交到本地倉庫
    [master 8a4e57d] add new test2.txt
     1 file changed, 3 insertions(+)
     create mode 100644 test2.txt
    $ WebService % ls -l //查看當前檔案夾檔案
    total 16
    -rw-r--r--  1 jack  staff   27 Sep 27 07:11 test2.txt
    -rw-r--r--  1 jack  staff  134 Sep 26 22:33 testGit.txt
    $ WebService % git status //查看git狀態
    On branch master
    nothing to commit, working tree clean
    $ WebService %             
    $ WebService % 
    $ WebService % 
    $ WebService % rm test2.txt //4.本地物理洗掉檔案
    $ WebService % ls -l //5.洗掉后確認
    total 8
    -rw-r--r--  1 jack  staff  134 Sep 26 22:33 testGit.txt
    $ WebService % git status //6.查看洗掉后
    On branch master
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
        deleted:    test2.txt //紅色字體,表示這個操作沒有被添加到暫存區
    
    no changes added to commit (use "git add" and/or "git commit -a")
    $ WebService % git add test2.txt //7.將洗掉后的狀態添加到暫存區
    $ WebService % git status //查看添加后的git狀態
    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
        deleted:    test2.txt //文字為綠色,表示暫存區已被更新,
    
    $ WebService % git commit -m "delete file test2.txt" test2.txt //8.把暫存區內容提交到本地倉庫
    [master f8373c4] delete file test2.txt
     1 file changed, 3 deletions(-)
     delete mode 100644 test2.txt
    $ WebService % git status //查看git狀態
    On branch master
    nothing to commit, working tree clean
    $ WebService % ls
    testGit.txt
    $ WebService % git reflog //9.查看日志資訊
    f8373c4 (HEAD -> master) HEAD@{0}: commit: delete file test2.txt //10/1檔案被洗掉的歷史記錄
    8a4e57d HEAD@{1}: commit: add new test2.txt
    d3c9608 HEAD@{2}: reset: moving to d3c9608
    d3c9608 HEAD@{3}: reset: moving to d3c9608
    148942f HEAD@{4}: reset: moving to 148942f
    9dba7c5 HEAD@{5}: reset: moving to HEAD~2
    d3c9608 HEAD@{6}: reset: moving to d3c9608
    c970a17 HEAD@{7}: reset: moving to HEAD^^
    9dba7c5 HEAD@{8}: reset: moving to HEAD^
    364024e HEAD@{9}: reset: moving to 364024e
    9dba7c5 HEAD@{10}: reset: moving to 9dba7c5
    d3c9608 HEAD@{11}: commit: this is my fifth updata,updata testGit.txt
    364024e HEAD@{12}: commit: this is my fourth commit,updata testGit.txt
    9dba7c5 HEAD@{13}: commit: this is my third commit,updata testGit.txt
    148942f HEAD@{14}: commit: this is my second commit, modify testGit.txt
    c970a17 HEAD@{15}: commit (initial): first commit:new file testGit.txt
    $ WebService % git reset --hard 8a4e57d  //2.恢復到洗掉之前的版本
    HEAD is now at 8a4e57d add new test2.txt
    $ WebService % ls -l//3.查看本地檔案是否恢復?
    total 16
    -rw-r--r--  1 jack  staff   27 Sep 27 07:25 test2.txt//檔案又被恢復回來了
    -rw-r--r--  1 jack  staff  134 Sep 26 22:33 testGit.txt
    $ WebService %
    復制代碼

恢復暫存區的檔案

  • 說明
    使暫存區檔案恢復
  • 命令
    git reset --hard HEAD
    通過上面重繪讓三個區保持一致即可
  • 條件
    要恢復的檔案提交到了本地庫

版本比較

比較作業區和暫存區

  • 命令

    git diff 檔案名

  • 使用例

    比較修改后的test2.txt的作業區和暫存區

    作業區,暫存區,本地倉庫test2.txt內容一致

    aaaaaaaa
    bbbbbbbb
    cccccccc
    復制代碼

    修改后的作業區test2.txt

    aaaaaaaa
    bbbbbbbb
    cccccccc@@@@@@
    復制代碼

    比較后結果

    $ WebService % git diff test2.txt
    diff --git a/test2.txt b/test2.txt
    index 092b923..0c08686 100644
    --- a/test2.txt
    +++ b/test2.txt
    @@ -1,3 +1,3 @@
     aaaaaaaa
     bbbbbbbb
    -cccccccc //-代表洗掉
    +cccccccc@@@@@@ //+代表追加,git是以行尾單位來管理版本的,所以cccccccc表示為洗掉,cccccccc@@@@@@表示為追加,
    $ WebService %
    復制代碼

    提交到暫存區后再比較

    $ WebService % git add test2.txt
    $ WebService % git diff test2.txt
    $ WebService %
    復制代碼

作業區和本地倉庫版本比較

  • 命令

    git diff 指定版本 [檔案名]

  • 指定版本

    HEAD:當前本地倉庫的版本

    HEAD^:本地倉庫的上一個版本

    HEAD^^:本地倉庫的上兩個版本

    HEAD~n:本地倉庫的上n個版本

    版本號的hash值

  • 注意

    檔案名不寫的話是所有當前檔案夾的所有檔案

  • 使用例

    作業區和本地倉庫的當前版本比較

    $ WebService % git reset --hard HEAD 
    //先把三個區同步一下,恢復到同一狀態
    HEAD is now at 8a4e57d add new test2.txt
    $ WebService % git status           
    On branch master
    nothing to commit, working tree clean
    $ WebService % cat test2.txt
    aaaaaaaa
    bbbbbbbb
    cccccccc
    $ WebService % vim test2.txt //對作業區修改
    $ WebService % git diff HEAD test2.txt//修改后進行比較
    diff --git a/test2.txt b/test2.txt
    index 092b923..0c08686 100644
    --- a/test2.txt
    +++ b/test2.txt
    @@ -1,3 +1,3 @@
     aaaaaaaa
     bbbbbbbb
    -cccccccc
    +cccccccc@@@@@@
    $ WebService %
    復制代碼

    和本地倉庫的上一個版本進行比較

    $ WebService % git diff HEAD^ test2.txt
    diff --git a/test2.txt b/test2.txt
    new file mode 100644
    index 0000000..0c08686
    --- /dev/null
    +++ b/test2.txt
    @@ -0,0 +1,3 @@
    +aaaaaaaa
    +bbbbbbbb
    +cccccccc@@@@@@
    $ WebService %
    復制代碼

分支

分支概述

在版本控制程序中,使用多條線同時推進多個任務,
復制代碼

分支好處

  • 同時推進多個功能開發,提高生產效率,
  • 各個分支在開發程序中,如有某個分支失敗,不會對其他分支有影響,失敗的分支可以重新獲取mastaer分支,進行再次開發,

創建分支

  • 命令

  • 使用例

    git branch 分支名

    $ WebService % git branch hot_fix
    復制代碼

查看分支

  • 命令

    git branch -v

  • 使用例

    $ WebService % git branch -v     
    hot_fix 8a4e57d add new test2.txt
    * master  8a4e57d add new test2.txt
    //*所在的位值就是我們現在所以在的分支
    $ WebService %
    復制代碼

切換分支

  • 說明

    把分支從當前分支切換到其他分支

  • 命令

    git checkout 分支名

  • 使用例

    $ WebService % git checkout hot_fix
    Switched to branch 'hot_fix'
    $ WebService % git branch -v       
    * hot_fix 8a4e57d add new test2.txt //現在已經切換到hot_fix分支
    master  8a4e57d add new test2.txt
    $ WebService %
    復制代碼

合并分支

  • 說明

    把指定分支的內容合并到當前分支

  • 命令

    git merge 要合并內容的分支名

    $ WebService % git branch -v
    //查看當前分支
    * hot_fix a360edf hox_fix one add
    master  8a4e57d add new test2.txt
    $ WebService % git checkout master
    //切換到內容要合并到的分支
    Switched to branch 'master'
    $ WebService % git branch -v 
    //再次確認切換后的分支
    hot_fix a360edf hox_fix one add
    * master  8a4e57d add new test2.txt
    $ WebService % git merge hot_fix
    //進行分支合并
    Updating 8a4e57d..a360edf
    Fast-forward
    test2.txt | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
    $ WebService % cat test2.txt//查看合并后的內容
    aaaaaaaa
    bbbbbbbb
    cccccccc edit by hox_fix//次內容是hot_fix分支內容,證明已經合并成功,
    $ WebService % git branch -v    
    hot_fix a360edf hox_fix one add   //當兩個分支內容一樣的時候,此時兩個分支的hash值是一樣的,
    * master  a360edf hox_fix one add //當兩個分支內容一樣的時候,此時兩個分支的hash值是一樣的,
    $ WebService %
    復制代碼

解決合并沖突

  • 說明

    當要合并兩個分支的時候,兩個分支修改內容不一樣,導致不能自動進行合并操作,所以需要手動進行合并操作,

  • 解決思路

    1.洗掉沖突檔案內容的特殊符號

    2.修改沖突內容

    3.修改后的檔案添加到暫存區,(git add 檔案名)

    4.從暫存區提交到本地倉庫,

    (命令:git commit -m "注釋") 注:這里的commit命令不能帶檔案名稱引數,

    $ WebService % vim test2.txt //修改mster分支的test2檔案
    $ WebService % git add test2.txt
    //把修改后的檔案添加到暫存區
    $ WebService % git commit test2.txt
    //把暫存區檔案提交到本地倉庫
    [master 4a902f1] updata master
     1 file changed, 1 insertion(+)
    $ WebService % git branch -v
    //查看當前分支
      hot_fix a360edf hox_fix one add
    * master  4a902f1 updata master
    $ WebService % 
    $ WebService % git checkout hot_fix
    //切換到hot_fix分支
    Switched to branch 'hot_fix'
    $ WebService % git branch -v //查看分支       
    * hot_fix a360edf hox_fix one add
    master  4a902f1 updata master
    $ WebService % vim test2.txt //編輯test2.txt
    $ WebService % git add test2.txt //修改后的檔案添加到暫存區
      $ WebService % git commit -m "updata hox_fix" test2.txt //提交檔案到本地倉庫
    [hot_fix ee3ae4c] updata hox_fix
     1 file changed, 1 insertion(+)
    $ WebService % 
    $ WebService % git merge master          //合并分支
    Auto-merging test2.txt
    CONFLICT (content): Merge conflict in test2.txt 
    Automatic merge failed; fix conflicts and then commit the result.
    //自動合并分支失敗,接下來需要手動修改檔案后在進行提交來解決沖突
    $ WebService % ls -l
    total 16
    -rw-r--r--  1 jack  staff  126 Sep 27 11:02 test2.txt
    -rw-r--r--  1 jack  staff  134 Sep 26 22:33 testGit.txt
    $ WebService % vim test2.txt                       //打開檔案進行手動合并檔案內容
    $ WebService % git status
    //查看git狀態
    On branch hot_fix //在hot_fix分支上
    You have unmerged paths.//沒有合并的路徑
      (fix conflicts and run "git commit") //修理沖突并執行
      (use "git merge --abort" to abort the merge) //終止合并
    
    Unmerged paths:
      (use "git add <file>..." to mark resolution) //使用git add <file> 命令去標記為解決
        both modified:   test2.txt
    
    no changes added to commit (use "git add" and/or "git commit -a")
    $ WebService % git add test2.txt
    //解決沖突后的檔案添加到暫存區
    $ WebService % git status       
    On branch hot_fix
    All conflicts fixed but you are still merging.//所有的沖突已經解決了,但是你仍然處于“合并中”狀態,
      (use "git commit" to conclude merge)
    //使用git commit 命令去變換”合并中“的狀態
    
    Changes to be committed:
        modified:   test2.txt
    
    $ WebService % git commit -m "resolve conflict" test2.txt
    fatal: cannot do a partial commit during a merge.
    //注意:在這中特殊場合下的commit不能再后面使用檔案名
    $ WebService % git commit -m "resolve conflict"
    //去掉檔案名再次執行提交,
    [hot_fix 0d62477] resolve conflict //沖突解決了,
    $ WebService % git status
    //查看git狀態
    On branch hot_fix
    nothing to commit, working tree clean
    $ WebService % vim test2.txt
    //確認合并后的內容
    $ WebService %
    復制代碼

    上面執行完merge命令后,test2.txt檔案的內容,

    aaaaaaaa
    bbbbbbbb
    cccccccc edit by hox_fix
    <<<<<<< HEAD  //指標版本內容
    eeeeeeee add by hox_fix
    =======
    dddddddd add by master
    >>>>>>> master  //master版本內容
    復制代碼

    上面修改后的檔案內容

    aaaaaaaa
    bbbbbbbb
    cccccccc edit by hox_fix
    dddddddd add by master
    eeeeeeee add by hox_fix
    復制代碼

遠程庫操作

注冊賬戶

  • 注冊github賬戶
  • 注冊碼云賬戶
  • 兩個賬戶任意一個即可

創建專案倉庫

  • 創建新倉庫

    (在這里不做敘述)

遠程倉庫別名設定

  • 說明

    起別名的目的為了在推送到遠程倉庫的時候比較簡單,不至于敲很長的地址,

  • 命令

    git remote add 別名 遠程倉庫地址.git

  • 使用例

    $ WebService % git remote add origin https://github.com/jack2019/WebService.git
    $ WebService %
    復制代碼

查看遠程倉庫別名資訊

  • 說明

    在設定遠程倉庫別名后,查看設定是否成功,

  • 命令

    git remote -v

  • 使用例

    $ WebService % git remote -v
        origin  https://github.com/jack2019/WebService.git (fetch)
        origin  https://github.com/jack2019/WebService.git (push)
    $ WebService %
    復制代碼

推送到遠程倉庫

  • 說明

    把本地倉庫的內容上傳到遠程倉庫

  • 命令

    git push 遠程庫別名 分支名

  • 使用例

    $ WebService % git push origin hot_fix
    Enumerating objects: 30, done.
    Counting objects: 100% (30/30), done.
    Delta compression using up to 16 threads
    Compressing objects: 100% (22/22), done.
    Writing objects: 100% (30/30), 2.52 KiB | 1.26 MiB/s, done.
    Total 30 (delta 4), reused 0 (delta 0)
    remote: Resolving deltas: 100% (4/4), done.
    remote: 
    remote: Create a pull request for 'hot_fix' on GitHub by visiting:
    remote:      https://github.com/jack2019/WebService/pull/new/hot_fix
    remote: 
    To https://github.com/jack2019/WebService.git
     * [new branch]      hot_fix -> hot_fix
    $ WebService %
    復制代碼

推送發生失敗

  • 當推送到遠程倉庫時莫名發生失敗,此時可以進行強行推送

  • 命令

    git push 遠程倉庫名稱.git 分支名 -f

  • 使用例

    $ WebService % git push origin master //首次推送
    To https://github.com/jack2019/WebService.git
     ! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'https://github.com/jack2019/WebService.git' //推送失敗
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    $ WebService % git push origin master -f //進行強行推送
    Total 0 (delta 0), reused 0 (delta 0)
    To https://github.com/jack2019/WebService.git
     + 6cfbddc...4a902f1 master -> master (forced update) //強行推送成功,可以去github倉庫查看是否已經有上傳的內容,
    $ WebService %
    復制代碼

遠程倉庫克隆

  • 說明

    當我們想從github或者碼云下載他人的專案進行學習閱讀的時候,我們可以使用克隆命令,

  • 命令

    git clone 遠程倉庫地址

  • 注意

    克隆操作在完成下載檔案到本地的同時還完成了兩件事情,分別是初始化遠程倉庫別名,初始話本地倉庫(也就是git init命令執行程序,)

  • 使用例

    ?  IdeaProjects git clone https://github.com/jack2019/gitLearnning.git //克隆遠程倉庫庫
    Cloning into 'gitLearnning'...
    remote: Enumerating objects: 52, done.
    remote: Counting objects: 100% (52/52), done.
    remote: Compressing objects: 100% (34/34), done.
    remote: Total 52 (delta 10), reused 51 (delta 10), pack-reused 0
    Unpacking objects: 100% (52/52), done. //克隆成功
    ?  IdeaProjects cd gitLearnning //進入下載的檔案夾
    ?  gitLearnning git:(master) ls -al //查看下載的檔案
    total 16
    drwxr-xr-x   5 jack  staff  160 Oct  6 21:34 .
    drwxr-xr-x@ 21 jack  staff  672 Oct  6 21:34 ..
    drwxr-xr-x  13 jack  staff  416 Oct  6 21:34 .git
    -rw-r--r--   1 jack  staff  219 Oct  6 21:34 test2.txt
    -rw-r--r--   1 jack  staff  134 Oct  6 21:34 testGit.txt
    ?  gitLearnning git:(master) git status //查看git狀態
    On branch master
    Your branch is up to date with 'origin/master'. //被下載到了origin/master下
    
    nothing to commit, working tree clean
    ?  gitLearnning git:(master)
    復制代碼

從遠程庫拉取最新的內容

fetch操作

  • 說明

    遠程庫的內容被更新后,我們想取得最新的到本地,這時候就用到了fetch命令,如果我們還想和本地的版本進行合并,我們還需要使用merge命令進行合并,

  • 命令

    git fetch 遠程倉庫別名 分支名

  • 使用例

    $ git fetch origin master //抓取內容
      remote: Enumerating objects: 5, done.
      remote: Counting objects: 100% (5/5), done.
      remote: Compressing objects: 100% (2/2), done.
      remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
      Unpacking objects: 100% (3/3), done.
      From https://github.com/jack2019/WebService
       * branch            master     -> FETCH_HEAD
         f1a3142..da6a4ee  master     -> origin/master
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ ls -l
      total 2
      -rw-r--r-- 1 laofan 197121 100 九月 28 21:30 test2.txt
      -rw-r--r-- 1 laofan 197121 144 九月 28 21:30 testGit.txt
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ cat test2.txt
      aaaaaaaa
      bbbbbbbb
      cccccccc edit by hox_fix
      dddddddd add by master
    
      mmmmmmm push after updata!
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ git checkout origin/master //fetch下來的內容放在origin/master下,切換分支到origin、master下,
      Note: checking out 'origin/master'.
    
      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 da6a4ee... mac commit ,window fetch
    
      Window-PC MINGW64 /e/workspace/web/webservice ((da6a4ee...))
      $ git branch -v //查看當前分支
      * (HEAD detached at origin/master) da6a4ee mac commit ,window fetch
        master f1a3142 [behind 1] push after updata test2.txt //當前所處的分支是origin/master下
    
      Window-PC MINGW64 /e/workspace/web/webservice ((da6a4ee...))
      $ cat test2.txt //查看當前分支下的檔案內容
      aaaaaaaa
      bbbbbbbb
      cccccccc edit by hox_fix
      dddddddd add by master
    
      mmmmmmm push after updata
      nnnnnnn macbook add! //當前分支新追加的內容
    
      Window-PC MINGW64 /e/workspace/web/webservice ((da6a4ee...))
      $ git checkout master  //切換分支到master
      Previous HEAD position was da6a4ee... mac commit ,window fetch
      Switched to branch 'master'
      Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
        (use "git pull" to update your local branch)
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ git branch -v //查看當前分支
      * master f1a3142 [behind 1] push after updata test2.txt
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ cat test2.txt //查看當前分支內容
      aaaaaaaa
      bbbbbbbb
      cccccccc edit by hox_fix
      dddddddd add by master
    
      mmmmmmm push after updata!
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ git merge origin/master  //把origin/master分支內容合并到master
      Updating f1a3142..da6a4ee
      Fast-forward
       test2.txt | 3 ++-
       1 file changed, 2 insertions(+), 1 deletion(-)
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
      $ cat test2.txt //查看合并后的master分支檔案內容
      aaaaaaaa
      bbbbbbbb
      cccccccc edit by hox_fix
      dddddddd add by master
    
      mmmmmmm push after updata
      nnnnnnn macbook add! //origin/master追加的內容
    
      Window-PC MINGW64 /e/workspace/web/webservice (master)
    復制代碼

pull操作

  • 說明

    pull操作等價于fetch操作 + merge操作

  • 命令

    git pull 遠程倉庫別名 分支名

  • 使用例

    $ git pull origin master
    remote: Enumerating objects: 5, done.
    remote: Counting objects: 100% (5/5), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    From https://github.com/jack2019/WebService
     * branch            master     -> FETCH_HEAD
       da6a4ee..494ed55  master     -> origin/master
    Updating da6a4ee..494ed55
    Fast-forward
     test2.txt | 1 +
     1 file changed, 1 insertion(+)
    
    Window-PC MINGW64 /e/workspace/web/webservice (master)
    $ cat test2.txt
    aaaaaaaa
    bbbbbbbb
    cccccccc edit by hox_fix
    dddddddd add by master
    
    mmmmmmm push after updata
    nnnnnnn macbook add!
    jjjjjjj macbook add2!
    
    Window-PC MINGW64 /e/workspace/web/webservice (master)
    $
    復制代碼

協同開發沖突的解決

  • 說明
    如果不基于遠程庫最新版本進行修改的話則不能推送,必須先拉取最新的遠程庫,拉取后發生沖突,則按照“分支沖突解決”的操作即可,
  • 例子
    mac端更新后提交github
    window端不拉取最新的github直接更新進行提交github,此時需要先拉取最新的遠程庫進行,并進行遠程庫和本地庫的合并,

跨團隊協作

  • 說明
    當需要團隊外部的人員進行代碼的變更時,由于團隊外的人沒有push的權限,所以需要團隊外人員對專案進行fork操作,
  • 正常流程
    1.github用戶1fork用戶2的專案
    (fork之后,在遠程庫自動創建一個同樣的專案)
    2.clone到本地
    3.本地修改內容
    4.提交到暫存區,本地庫
    5.push到github用戶1
    6.向用戶2申請提交請求
    pull requests
    new pull request
    7.用戶2進行pull requestes的處理,并進行merge操作,

git知識補充

  • Q:當不小心對整個系統的檔案夾進行git inint操作后該如何取消?
    A:通過命令rm -rf .git對git檔案進行洗掉操作就即可,
  • Q:如何查看幫助檔案?
    A:通過命令git help 要查看的命令 進行查看即可,

--做了一些思維導圖的筆記,結果不能正常顯示,太可惜了,有機會補上!!!

看完三件事??

如果你覺得這篇內容對你還蠻有幫助,我想邀請你幫我三個小忙:

  1. 點贊,轉發,有你們的 『點贊和評論』,才是我創造的動力,

  2. 關注公眾號 『 java爛豬皮 』,不定期分享原創知識,

  3. 同時可以期待后續文章ing??



轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/172102.html

標籤:Java

上一篇:什么會導致Java應用程式的CPU使用率飆升?

下一篇:身為程式員,你是不是也問過這3個問題?

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more