<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                Git基于命令行的常規操作 ? 初始化本地git環境 #!/bin/bash username=$1 email=$2 git=/usr/bin/git if [ $# -ne 2 ];then echo $"Usage:$0 <Username> <Email>" exit 2 fi $git config --global user.name "$username" $git config --global user.email "$email" $git config --global color.ui true $git config --global alias.olog "log --pretty=oneline" $git config --global alias.plog "log -p" 說明:SHA1:是git 對象中的40位hash編碼數 ? 文件提交 Git add index.html(多個文件,就用點號.) Git commit –m “add index.html” ? 文件重命名 [root@localhost test]# git mv pay.html pay.php [root@localhost test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: pay.html -> pay.php ? 撤銷工作區的修改 git checkout -- news.html ? 從暫存區中刪除,工作目錄保留 git rm --cached test.bin ? 撤銷提交到工作區(版本回退到工作區) git reset --mixed HEAD^ 或者 git reset --mixed SHA1 ? 撤銷提交到暫存區(版本回退到暫存區) Git reset –soft HEAD^ 或者 git reset –soft SHA1 ? 將工作區、暫存區和版本庫恢復到指定版本 [root@localhost test]# git reset --hard cd6495c HEAD is now at cd6495c news01.html (執行這個操作,做好在其他窗口執行git log –oneline) ? 查看某個文件的散列值和版本庫里的內容 [root@localhost test]# git hash-object -w about3.html 641d57406d212612a9e89e00db302ce758e558d2 [root@localhost test]# git cat-file -p 641d57 111 222 333 ? 查看某個文件是誰提交或誰修改的 作用:查看文件內容是誰添加 案例:我想查看about3.html這個文件第二行是誰提交的 [root@localhost test]# cat about3.html 111 222 333 [root@localhost test]# git blame about3.html -L 2,+1 400fa95a (louis 2018-04-19 15:52:20 +0800 2) 222 ? 查看某個文件的修改歷史 git log -C news.html ? 提交查找 [root@localhost test]# git grep --name-only news (查看包含news的文件名) news.html news01.html [root@localhost test]# git grep -n news (查看包含news的文件名,并顯示該內容在第幾行) news.html:1:news center news01.html:1:news center 分支管理 ? 本地新建分支 [root@localhost test]# git branch dev [root@localhost test]# git checkout dev Switched to branch 'dev' 注意:我們可以基于任意一次提交來創建分支 [root@localhost test]# git log --oneline dd97293 rename pay.html pay.htm cd6495c news01.html b20d55e add detail.html 400fa95 squash commit about3.html c9bd929 abount2 bbe4912 about 7fecdff pay 9770bad news 72dc15a first commit [root@localhost test]# git branch pay 7fecdff [root@localhost test]# git checkout pay Switched to branch 'pay' [root@localhost test]# ll total 12 -rw-r--r--. 1 root root 0 Apr 23 13:16 clib.a drwxr-xr-x. 2 root root 45 Apr 23 13:19 doc -rw-r--r--. 1 root root 31 Apr 19 16:11 index.html -rw-r--r--. 1 root root 12 Apr 23 14:53 news.html -rw-r--r--. 1 root root 26 Apr 23 16:27 pay.html -rw-r--r--. 1 root root 0 Apr 23 10:23 test.bin -rw-r--r--. 1 root root 0 Apr 23 13:14 test.o ? 刪除分支 對于已經合并的分支 git branch –d dev 對于沒有合并的分支 git branch –D dev ? 分支重命名 git branch –m dev Dev ? 查看哪些分支沒有被合并 Git branch –no-merged ? 分支儲藏 作用:當你正在一個分支上寫代碼,但是此時突然有個緊急事情需要處理,然后當前分支上的代碼又不能提交,這個時候就會用到儲藏的功能 [root@localhost test]# touch stash.txt [root@localhost test]# echo "statsh:add1" >> stash.txt [root@localhost test]# git add stash.txt [root@localhost test]# git stash (把之前沒有提交的代碼暫存起來) Saved working directory and index state WIP on dev: dd97293 rename pay.html pay.htm HEAD is now at dd97293 rename pay.html pay.htm [root@localhost test]# git checkout -b bug (然后切換到其他分支,開始修復bug,修復完畢后,合并到主分支) Switched to a new branch 'bug' [root@localhost test]# git checkout dev (bug修復完,并合并到主分支后,然后再切換到dev分支,開始之前的開發) Switched to branch 'dev' [root@localhost test]# git stash pop 彈出 [root@localhost test]# git stash list ? 如果不知道想要恢復分支的散列值,可以通過reflog [root@localhost test]# git reflog dd97293 HEAD@{0}: checkout: moving from bug to dev dd97293 HEAD@{1}: checkout: moving from dev to bug dd97293 HEAD@{2}: checkout: moving from master to dev ? 合并分支(merge) 一) 快進式合并 [root@localhost test]# git branch -a bug * dev master pay [root@localhost test]# git commit -m "add stats" [dev 1cef480] add stats 1 file changed, 1 insertion(+) create mode 100644 stash.txt [root@localhost test]# git checkout master Switched to branch 'master' [root@localhost test]# git merge dev Updating dd97293..1cef480 Fast-forward stash.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 stash.txt 二) 合并提交 場景:當主分支和dev分支同時又內容提交的時候,我們需要把dev分支合并到master分支,這個時候使用git merge,就會生成一個新的commit對象 Git merge dev ? 壓合合并 場景:將一個分支上的所有歷史提交合并成一個提交,然后合并到另一個分支,一般用于修改bug或某個小型功能分支 git merge –squash bug git commit ? 分支衍合 場景:基于某個開源軟件做二次開發。當我們在基于開源軟件做二次開發的時候,這個時候開源軟件master分支也在不斷的更新,此時我們需要使用開源軟件的master分支,我們就可以通過git rebase把master分支合并到我們的分支上 1)先切換到自己的分支(dev) 2)Git rebase master ? 推送分支到遠程 [root@linux7-node2 app01]# git checkout dev Switched to branch 'dev' [root@linux7-node2 app01]# git push origin dev:dev Counting objects: 4, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 293 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@git.51yuki.cn:java01/app01.git * [new branch] dev -> dev ? 拉取遠程分支并創建本地分支 [root@linux7-node2 app01]# git fetch origin bug:Newbug (遠程分支bug,本地分支Newbug) 該方法本地不會自動切換到Newbug分支 ? 基于本地分支建立一個于遠程分支的關聯 [root@linux7-node2 app01]# git branch -a Newbug * dev master remotes/origin/dev remotes/origin/master [root@linux7-node2 app01]# git checkout Newbug [root@linux7-node2 app01]# git push origin Newbug:bug Everything up-to-date [root@linux7-node2 app01]# git branch -a * Newbug dev master remotes/origin/bug remotes/origin/dev remotes/origin/master
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看