您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“git撤銷(xiāo)的用法”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“git撤銷(xiāo)的用法”吧!
撤銷(xiāo)本地修改
[root@xuhx-02 git_project]# git status # 位于分支 master # 尚未暫存以備提交的變更: # (使用 "git add <file>..." 更新要提交的內(nèi)容) # (使用 "git checkout -- <file>..." 丟棄工作區(qū)的改動(dòng)) # # 修改: README.md # 修改尚未加入提交(使用 "git add" 和/或 "git commit -a") [root@xuhx-02 git_project]# git checkout -- README.md [root@xuhx-02 git_project]# git status # 位于分支 master 無(wú)文件要提交,干凈的工作區(qū)
撤銷(xiāo)git add
[root@xuhx-02 git_project]# git add 01.sh [root@xuhx-02 git_project]# git status # 位于分支 master # 要提交的變更: # (使用 "git reset HEAD <file>..." 撤出暫存區(qū)) # # 新文件: 01.sh # [root@xuhx-02 git_project]# git reset HEAD 01.sh [root@xuhx-02 git_project]# git status # 位于分支 master # 未跟蹤的文件: # (使用 "git add <file>..." 以包含要提交的內(nèi)容) # # 01.sh 提交為空,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤)
撤銷(xiāo)commit
[root@xuhx-02 git_project]# git commit -m "add 01.sh" [master 9d8cbe9] add 01.sh 1 file changed, 10 insertions(+) create mode 100644 01.sh
--mixed :不刪除工作空間改動(dòng)代碼,撤銷(xiāo)commit,并且撤銷(xiāo)git add . 操作
[root@xuhx-02 git_project]# git reset --mixed HEAD^ [root@xuhx-02 git_project]# git status # 位于分支 master # 未跟蹤的文件: # (使用 "git add <file>..." 以包含要提交的內(nèi)容) # # 01.sh 提交為空,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤)
--soft :不刪除工作空間改動(dòng)代碼,撤銷(xiāo)commit,不撤銷(xiāo)git add .
[root@xuhx-02 git_project]# git reset --soft HEAD^ [root@xuhx-02 git_project]# git status # 位于分支 master # 要提交的變更: # (使用 "git reset HEAD <file>..." 撤出暫存區(qū)) # # 新文件: 01.sh #
--hard :刪除工作空間改動(dòng)代碼,撤銷(xiāo)commit,撤銷(xiāo)git add .注意完成這個(gè)操作后,就恢復(fù)到了上一次的commit狀態(tài)。
[root@xuhx-02 git_project]# git reset --hard f51b0fdfa6846f88b90ac76e7975594bdd887576 HEAD 現(xiàn)在位于 f51b0fd add readme [root@xuhx-02 git_project]# ls README.md
--amend:修改的文件已被git commit,但想再次修改不再產(chǎn)生新的Commit
# 重新提交 $ git add sample.txt $ git commit --amend -m"說(shuō)明"
清除工作空間 git clean
[root@xuhx-02 git_project]# git clean -n 將刪除 01.sh
參考git 撤銷(xiāo)回滾學(xué)習(xí)
到此,相信大家對(duì)“git撤銷(xiāo)的用法”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。