柚子快報(bào)激活碼778899分享:Git源碼管理
參考視頻:16-git的日志以及版本管理_嗶哩嗶哩_bilibili
參考博客:Git && Docker 學(xué)習(xí)筆記-CSDN博客
目錄
簡介
個(gè)人操作初始化
初始化git目錄
查看生成的git目錄文件
配置git工作目錄的用戶信息
查看工作區(qū)的狀態(tài),生成文件的狀態(tài)
添加文件到暫存區(qū)、倉庫區(qū)
倉庫區(qū)的版本回退和恢復(fù)
暫存區(qū)回退到工作區(qū)
工作區(qū)及暫存區(qū)修改的撤銷
遠(yuǎn)程倉庫克隆到本地初始化
遠(yuǎn)程倉庫的文件創(chuàng)建與上傳及信息查詢
Git 多人操作
多人協(xié)助沖突的發(fā)生及解決
標(biāo)簽
分支操作
簡介
當(dāng)前最先進(jìn)的分布式版本控制系統(tǒng),作用于源代碼管理,方便多人協(xié)同開發(fā),便于版本控制
個(gè)人操作初始化
初始化git目錄
git init
root@pass:/home/pass/Desktop/mytest# git init????????? 初始化目錄生成 .git目錄 hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint:?? git config --global init.defaultBranch
查看生成的git目錄文件
ll???????? 查看隱藏目錄命令
root@pass:/home/pass/Desktop/mytest# ll???????? 查看隱藏目錄命令ll total 12 drwxr-xr-x 3 root root 4096? 3月? 1 20:00 ./ drwxr-xr-x 4 pass pass 4096? 3月? 1 20:00 ../ drwxr-xr-x 7 root root 4096? 3月? 1 20:00 .git/????? 以點(diǎn)開頭的目錄系統(tǒng)不可見 root@pass:/home/pass/Desktop/mytest# cd .git/ root@pass:/home/pass/Desktop/mytest/.git# ls branches? config? description? HEAD? hooks? info? objects? refs
配置git工作目錄的用戶信息
git config user.name pass??? 用戶姓名
git config user.email pass@qq.com? 用戶郵件
root@pass:/home/pass/Desktop/mytest/.git# git config user.name pass??? 用戶姓名 root@pass:/home/pass/Desktop/mytest/.git# git config user.email pass@qq.com? 用戶郵件 root@pass:/home/pass/Desktop/mytest/.git# cat config???? 查看用戶信息 [core] ??????? repositoryformatversion = 0 ??????? filemode = true ??????? bare = false ??????? logallrefupdates = true [user] ??????? name = pass ??????? email = pass@qq.com
查看工作區(qū)的狀態(tài),生成文件的狀態(tài)
git status????? 查看當(dāng)前狀態(tài)
root@pass:/home/pass/Desktop/mytest# git status????? 查看當(dāng)前狀態(tài) On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track) root@pass:/home/pass/Desktop/mytest# touch file????? 工作區(qū)創(chuàng)建文件 root@pass:/home/pass/Desktop/mytest# git status On branch master
No commits yet
Untracked files: ? (use "git add
nothing added to commit but untracked files present (use "git add" to track)
添加文件到暫存區(qū)、倉庫區(qū)
git add file???????????????????????????? 添加文件file到暫存區(qū) "."當(dāng)前全部文件
git commit -m 'first commit'?? 提交到倉庫[參數(shù)-m 備注信息]
git log?????????????????????????? ? ? ? ?? 查看提交日志
root@pass:/home/pass/Desktop/mytest# git add file?? 添加文件file 到暫存區(qū)"."當(dāng)前全部文件 root@pass:/home/pass/Desktop/mytest# git status???? 查看當(dāng)前狀態(tài) On branch master
No commits yet
Changes to be committed: ? (use "git rm --cached
Untracked files: ? (use "git add
root@pass:/home/pass/Desktop/mytest# git commit -m 'first commit'?? 提交到倉庫[-m 備注] [master (root-commit) 474ca08] first commit ?1 file changed, 0 insertions(+), 0 deletions(-) ?create mode 100644 file root@pass:/home/pass/Desktop/mytest# git status On branch master Untracked files: ? (use "git add
nothing added to commit but untracked files present (use "git add" to track) root@pass:/home/pass/Desktop/mytest# git log??????????????????????????? 查看日志 commit 474ca0871818584972749d6b84d2d814825d8b2f (HEAD -> master) Author: pass
??? first commit
倉庫區(qū)的版本回退和恢復(fù)
回退版本
HEAD?? 當(dāng)前最新版本HEAD^? 當(dāng)前最新版本的前一個(gè)版本HEAD^^ 當(dāng)前最新版本的前兩個(gè)版本,依次類推HEAD~1 當(dāng)前最新版本的前一個(gè)版本HEAD~10 當(dāng)前版本的前10個(gè)版本,依次類推
eg:?
git reset? --hard? HEAD~??? 回退到上一個(gè)版本
git reset? --hard? 版本號? ?? 回退到指定的版本
git reflog? ? ? ? ? ? ? ? ? ? ? ? ? ?? 查看所有的版本記錄
root@pass:/home/pass/Desktop/mytest# git reflog?? 查看所有的版本記錄 c9097f1 (HEAD -> master) HEAD@{0}: commit: second commit 474ca08 HEAD@{1}: commit (initial): first commit root@pass:/home/pass/Desktop/mytest# git reset --hard HEAD^?? 回退到上一版本 HEAD is now at 474ca08 first commit root@pass:/home/pass/Desktop/mytest# git log???????????????????????????? 查看提交的日志 commit 474ca0871818584972749d6b84d2d814825d8b2f (HEAD -> master) Author: pass
??? first commit root@pass:/home/pass/Desktop/mytest# git reflog 474ca08 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^ c9097f1 HEAD@{1}: commit: second commit 474ca08 (HEAD -> master) HEAD@{2}: commit (initial): first commit root@pass:/home/pass/Desktop/mytest# git reset --hard c9097f1?? 回退到第二個(gè)版本 HEAD is now at c9097f1 second commit
暫存區(qū)回退到工作區(qū)
git reset HEAD [file]
root@pass:/home/pass/Desktop/mytest# git status On branch master Changes to be committed: ? (use "git restore --staged
root@pass:/home/pass/Desktop/mytest# git reset HEAD learn.txt root@pass:/home/pass/Desktop/mytest# git status On branch master Changes to be committed: ? (use "git restore --staged
Untracked files: ? (use "git add
工作區(qū)及暫存區(qū)修改的撤銷
git checkout learn.txt?? 撤銷工作區(qū)及暫存區(qū)的修改
root@pass:/home/pass/Desktop/mytest# git status?? 暫存區(qū)的文件learn.txt On branch master Changes to be committed: ? (use "git restore --staged
root@pass:/home/pass/Desktop/mytest# echo 888 >> learn.txt? 修改工作區(qū)的文件 root@pass:/home/pass/Desktop/mytest# cat learn.txt 666 999 888 root@pass:/home/pass/Desktop/mytest# git checkout learn.txt?? 撤銷工作區(qū)及暫存區(qū)的修改 Updated 1 path from the index root@pass:/home/pass/Desktop/mytest# cat learn.txt 666 999
遠(yuǎn)程倉庫克隆到本地初始化
git clone git@github.com:past-plus/learn_test.git
root@pass:/home/pass/remote_learn# git clone git@github.com:past-plus/learn_test.git Cloning into 'learn_test'...?? 克隆遠(yuǎn)程倉庫到本地 warning: You appear to have cloned an empty repository. root@pass:/home/pass/remote_learn# cd learn_test/ root@pass:/home/pass/remote_learn/learn_test# ll total 12 drwxr-xr-x 3 root root 4096? 3月? 1 21:24 ./ drwxr-xr-x 3 root root 4096? 3月? 1 21:24 ../ drwxr-xr-x 7 root root 4096? 3月? 1 21:24 .git/ root@pass:/home/pass/remote_learn/learn_test# cd .git/ root@pass:/home/pass/remote_learn/learn_test/.git# ls??? 遠(yuǎn)程倉庫的git配置 branches? config? description? HEAD? hooks? info? objects? refs root@pass:/home/pass/remote_learn/learn_test/.git# cat config?? 遠(yuǎn)程倉庫的配置信息 [core] ??????? repositoryformatversion = 0 ??????? filemode = true ??????? bare = false ??????? logallrefupdates = true [remote "origin"] ??????? url = git@github.com:past-plus/learn_test.git ??????? fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] ??????? remote = origin ??????? merge = refs/heads/main root@pass:/home/pass/remote_learn/learn_test# git config user.name pass?? 配置用戶信息 root@pass:/home/pass/remote_learn/learn_test# git config user.eamil pass@qq.com
遠(yuǎn)程倉庫的文件創(chuàng)建與上傳及信息查詢
git add .?? 提交到暫存區(qū)
git status? 查看當(dāng)前狀態(tài)
git commit -m 'test and learn'? 提交到倉庫
git push??? 上傳到遠(yuǎn)程倉庫
root@pass:/home/pass/remote_learn/learn_test# touch test.py learn.py? 創(chuàng)建文件 root@pass:/home/pass/remote_learn/learn_test# git add .?? 提交到暫存區(qū) root@pass:/home/pass/remote_learn/learn_test# git status? 查看當(dāng)前狀態(tài) On branch main
No commits yet
Changes to be committed: ? (use "git rm --cached
root@pass:/home/pass/remote_learn/learn_test# git commit -m 'test and learn'? 提交到倉庫 [main (root-commit) b7588d1] test and learn ?2 files changed, 0 insertions(+), 0 deletions(-) ?create mode 100644 learn.py ?create mode 100644 test.py root@pass:/home/pass/remote_learn/learn_test# git push??? 上傳到遠(yuǎn)程倉庫 Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 232 bytes | 232.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:past-plus/learn_test.git ?* [new branch]????? main -> main root@pass:/home/pass/remote_learn/learn_test# vim test.py? 更新文件信息,需要再次上傳 root@pass:/home/pass/remote_learn/learn_test# git commit -m 'test modified' On branch main Your branch is up to date with 'origin/main'.
Changes not staged for commit: ? (use "git add
no changes added to commit (use "git add" and/or "git commit -a") root@pass:/home/pass/remote_learn/learn_test# git add . root@pass:/home/pass/remote_learn/learn_test# git commit -m 'test modified' [main 9d0f8f9] test modified ?1 file changed, 2 insertions(+) root@pass:/home/pass/remote_learn/learn_test# git status On branch main Your branch is ahead of 'origin/main' by 1 commit. ? (use "git push" to publish your local commits)
nothing to commit, working tree clean root@pass:/home/pass/remote_learn/learn_test# git log? 查看提交日志 commit 9d0f8f9b493856ec917edd67807ad0676e12da9a (HEAD -> main) Author: pass <10752095+past_pass@user.noreply.gitee.com> Date:?? Fri Mar 1 21:35:20 2024 +0800
??? test modified
commit b7588d1d98bf2a1287904610bff4d92397393440 (origin/main) Author: pass <10752095+past_pass@user.noreply.gitee.com> Date:?? Fri Mar 1 21:30:52 2024 +0800
??? test and learn root@pass:/home/pass/remote_learn/learn_test# git reflog? 查看歷史版本 9d0f8f9 (HEAD -> main) HEAD@{0}: commit: test modified b7588d1 (origin/main) HEAD@{1}: commit (initial): test and learn root@pass:/home/pass/remote_learn/learn_test# git push?? 提交到遠(yuǎn)程倉庫 Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 303 bytes | 303.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:past-plus/learn_test.git ?? b7588d1..9d0f8f9? main -> main
?運(yùn)行結(jié)果:
Git 多人操作
git commit -am 'xxxx'??? 參數(shù)a 表示add添加到暫存區(qū)
git pull?????????????????????????? 拉取遠(yuǎn)程倉庫到工作區(qū)
員工a的操作
root@pass:/home/pass/gitee_test/test_a# git config user.name 'a'? 配置用戶信息 root@pass:/home/pass/gitee_test/test_a# git config user.name 'a@qq.com' root@pass:/home/pass/gitee_test/test_a# touch test.py root@pass:/home/pass/gitee_test/test_a# git add . root@pass:/home/pass/gitee_test/test_a# git status
root@pass:/home/pass/gitee_test/test_a# git commit -m 'test commit first'? 提交到倉庫 [master (root-commit) 7bc421c] test commit first ?1 file changed, 0 insertions(+), 0 deletions(-) ?create mode 100644 test.py root@pass:/home/pass/gitee_test/test_a# git push??? 上傳到遠(yuǎn)程倉庫 Username for 'https://gitee.com': past_pass Password for 'https://past_pass@gitee.com': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 226 bytes | 226.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-6.4] To https://gitee.com/past_pass/test.git ?* [new branch]????? master -> master
員工b
root@pass:/home/pass/gitee_test/test_b# git config user.name 'b' root@pass:/home/pass/gitee_test/test_b# git config user.email 'b@qq.com' root@pass:/home/pass/gitee_test/test_b# git pull remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), 206 bytes | 206.00 KiB/s, done. From https://gitee.com/past_pass/test ?* [new branch]????? master???? -> origin/master root@pass:/home/pass/gitee_test/test_b# ls test.py
多人協(xié)助沖突的發(fā)生及解決
造成的原因: 多人修改同一份代碼,需要先拉取最新的代碼修改,否則會造成沖突
員工a
root@pass:/home/pass/gitee_test/test_a# echo 'echo "git learn"'>>learn.py root@pass:/home/pass/gitee_test/test_a# cat learn.py echo "learn" echo "git learn" root@pass:/home/pass/gitee_test/test_a# git commit -am 'update learn' [master cda86ba] update learn ?1 file changed, 1 insertion(+) root@pass:/home/pass/gitee_test/test_a# git push
員工b[沒有pull拉取遠(yuǎn)程倉庫的代碼而是直接在本地進(jìn)行修改上傳造成沖突]
root@pass:/home/pass/gitee_test/test_b# cat learn.py echo "learn" echo "xxx" root@pass:/home/pass/gitee_test/test_b# git commit -am 'update file'
root@pass:/home/pass/gitee_test/test_b# git push
?? git:(test) git pull origin test ?* branch????????????? test?????? -> FETCH_HEAD hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint:?? git config pull.rebase false? # merge (the default strategy) hint:?? git config pull.rebase true?? # rebase hint:?? git config pull.ff only?????? # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches.
標(biāo)簽
當(dāng)一個(gè)大版本完成之后,需要打一個(gè)標(biāo)簽,記錄大版本備份代碼
git tag -a v1.0(標(biāo)簽名) -m 'version1.0'(描述) 本地打標(biāo)簽
git push origin v1.0(標(biāo)簽名)??????????????????????????????? 推送標(biāo)簽到遠(yuǎn)程倉庫
root@pass:/home/pass/gitee_test/test# git commit -am 'commit learn file' [master 62eda34] commit learn file ?1 file changed, 1 insertion(+), 1 deletion(-) root@pass:/home/pass/gitee_test/test# git tag -a v1.0 -m 'version1.0' root@pass:/home/pass/gitee_test/test# git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 278 bytes | 139.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-6.4] To https://gitee.com/past_pass/test.git ?? e1c4aef..62eda34? master -> master root@pass:/home/pass/gitee_test/test# git push origin v1.0
?運(yùn)行結(jié)果:
分支操作
git branch???????????????????????? 查看當(dāng)前分支
git checkout -b test????????? 創(chuàng)建并切換分支test
git checkout master???????? 切換主分支master
git merge test?????????????????? 融合分支test到主支master
root@pass:/home/pass/gitee_test/test# git branch * master root@pass:/home/pass/gitee_test/test# git checkout -b test Switched to a new branch 'test' root@pass:/home/pass/gitee_test/test# git branch ? master * test
root@pass:/home/pass/gitee_test/test# git checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. root@pass:/home/pass/gitee_test/test# git branch * master ? test
root@pass:/home/pass/gitee_test/test# git merge test Already up to date.
柚子快報(bào)激活碼778899分享:Git源碼管理
推薦閱讀
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。