<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 撤銷修改 自然,你是不會犯錯的。不過現在是凌晨兩點,你正在趕一份工作報告,你在`readme.txt`中添加了一行: ``` $ cat readme.txt Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. My stupid boss still prefers SVN. ``` 在你準備提交前,一杯咖啡起了作用,你猛然發現了“stupid boss”可能會讓你丟掉這個月的獎金! 既然錯誤發現得很及時,就可以很容易地糾正它。你可以刪掉最后一行,手動把文件恢復到上一個版本的狀態。如果用`git status`查看一下: ``` $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: readme.txt # no changes added to commit (use "git add" and/or "git commit -a") ``` 你可以發現,Git會告訴你,`git checkout -- file`可以丟棄工作區的修改: ``` $ git checkout -- readme.txt ``` 命令`git checkout -- readme.txt`意思就是,把`readme.txt`文件在工作區的修改全部撤銷,這里有兩種情況: 一種是`readme.txt`自修改后還沒有被放到暫存區,現在,撤銷修改就回到和版本庫一模一樣的狀態; 一種是`readme.txt`已經添加到暫存區后,又作了修改,現在,撤銷修改就回到添加到暫存區后的狀態。 總之,就是讓這個文件回到最近一次`git commit`或`git add`時的狀態。 現在,看看`readme.txt`的文件內容: ``` $ cat readme.txt Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. ``` 文件內容果然復原了。 `git checkout -- file`命令中的`--`很重要,沒有`--`,就變成了“切換到另一個分支”的命令,我們在后面的分支管理中會再次遇到`git checkout`命令。 http://michaelliao.gitcafe.io/video/discard-changes-of-working-dir.mp4 現在假定是凌晨3點,你不但寫了一些胡話,還`git add`到暫存區了: ``` $ cat readme.txt Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. My stupid boss still prefers SVN. $ git add readme.txt ``` 慶幸的是,在`commit`之前,你發現了這個問題。用`git status`查看一下,修改只是添加到了暫存區,還沒有提交: ``` $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: readme.txt # ``` Git同樣告訴我們,用命令`git reset HEAD file`可以把暫存區的修改撤銷掉(unstage),重新放回工作區: ``` $ git reset HEAD readme.txt Unstaged changes after reset: M readme.txt ``` `git reset`命令既可以回退版本,也可以把暫存區的修改回退到工作區。當我們用`HEAD`時,表示最新的版本。 再用`git status`查看一下,現在暫存區是干凈的,工作區有修改: ``` $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: readme.txt # no changes added to commit (use "git add" and/or "git commit -a") ``` 還記得如何丟棄工作區的修改嗎? ``` $ git checkout -- readme.txt $ git status # On branch master nothing to commit (working directory clean) ``` 整個世界終于清靜了! http://michaelliao.gitcafe.io/video/discard-changes-of-staged.mp4 現在,假設你不但改錯了東西,還從暫存區提交到了版本庫,怎么辦呢?還記得[版本回退](/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000)一節嗎?可以回退到上一個版本。不過,這是有條件的,就是你還沒有把自己的本地版本庫推送到遠程。還記得Git是分布式版本控制系統嗎?我們后面會講到遠程版本庫,一旦你把“stupid boss”提交推送到遠程版本庫,你就真的慘了…… ## 小結 又到了小結時間。 場景1:當你改亂了工作區某個文件的內容,想直接丟棄工作區的修改時,用命令`git checkout -- file`。 場景2:當你不但改亂了工作區某個文件的內容,還添加到了暫存區時,想丟棄修改,分兩步,第一步用命令`git reset HEAD file`,就回到了場景1,第二步按場景1操作。 場景3:已經提交了不合適的修改到版本庫時,想要撤銷本次提交,參考[版本回退](/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000)一節,不過前提是沒有推送到遠程庫。
                  <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>

                              哎呀哎呀视频在线观看