日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

git常见的回退操作

發布時間:2025/6/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 git常见的回退操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ? ? 有時候在操作git的時候,不免有時提交或修改過快,需要進行一些回退操作,下面來看一下。

lj@lj-virtual-machine:~/111111/git/gittest$ git status 位于分支 master 您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)尚未暫存以備提交的變更:(使用 "git add <文件>..." 更新要提交的內容)(使用 "git checkout -- <文件>..." 丟棄工作區的改動)修改: test.sh修改尚未加入提交(使用 "git add" 和/或 "git commit -a") lj@lj-virtual-machine:~/111111/git/gittest$ lj@lj-virtual-machine:~/111111/git/gittest$ git checkout -- test.sh lj@lj-virtual-machine:~/111111/git/gittest$ git status 位于分支 master 您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)無文件要提交,干凈的工作區

沒有執行git add操作之前,用git checkout -- test.sh執行回退操作。git中也有提示信息

lj@lj-virtual-machine:~/111111/git/gittest$ git status 位于分支 master 您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)要提交的變更:(使用 "git reset HEAD <文件>..." 以取消暫存)修改: test.shlj@lj-virtual-machine:~/111111/git/gittest$ git reset HEAD test.sh 重置后取消暫存的變更: M test.sh lj@lj-virtual-machine:~/111111/git/gittest$ git status 位于分支 master 您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)尚未暫存以備提交的變更:(使用 "git add <文件>..." 更新要提交的內容)(使用 "git checkout -- <文件>..." 丟棄工作區的改動)修改: test.sh修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

如果執行git add操作,用git reset HEAD test.sh進行回退

lj@lj-virtual-machine:~/111111/git/gittest$ git status 位于分支 master 您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)要提交的變更:(使用 "git reset HEAD <文件>..." 以取消暫存)修改: test.shlj@lj-virtual-machine:~/111111/git/gittest$ lj@lj-virtual-machine:~/111111/git/gittest$ git commit [master 31e8475] :qqqqqqq1 file changed, 1 insertion(+) lj@lj-virtual-machine:~/111111/git/gittest$ lj@lj-virtual-machine:~/111111/git/gittest$ lj@lj-virtual-machine:~/111111/git/gittest$ git log commit 31e8475fc86ff93c3050ff67135a6c3864a21bd3 Author: yaori <test@runoob.com> Date: Fri Mar 29 08:29:33 2019 +0800:qqqqqqqcommit e829ace82b18bf17f0b29cb751fbe5a226190135 Author: yaori <test@runoob.com> Date: Thu Mar 28 20:46:43 2019 +0800testcommit 78346b1f12fcbe366f873aa388defb247a55d5f2 Author: yaori <test@runoob.com> Date: Thu Mar 28 20:37:22 2019 +0800testcommit bfbbb585de8626fecfc4cd2afecf414f04637af2 Author: yaori <test@runoob.com> Date: Thu Mar 28 20:30:40 2019 +0800:wqcommit 0d4a4182f4ca18e14919727bbedffccc4f187ac7 Author: yaori <test@runoob.com> lj@lj-virtual-machine:~/111111/git/gittest$ git checkout e829ace82b18bf17f0b29cb751fbe5a226190135 Note: checking out 'e829ace82b18bf17f0b29cb751fbe5a226190135'.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_nameHEAD 目前位于 e829ace... test

如果你已經commit了修改,需要用git log找到上一個commit,再用git checkout commit id(上一個提交的)完成回退。如果你已經push到遠程分支,這樣不能回退遠程分支上的代碼。

總結

以上是生活随笔為你收集整理的git常见的回退操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。