zoukankan      html  css  js  c++  java
  • Git会用到但是你又记不住的一些命令

    最后一次commit信息写错了

    如果只是提交信息写错了信息,可以通过以下命令单独修改提交信息

    $ git commit --amend

    移除add过的文件

    #方法一 $ git rm --cache [文件名]

    #方法二 $ git reset head [文件/文件夹]

    回退本地commit(还未push)

    这种情况发生在你的本地仓库,可能你add,commit以后发现代码有点问题,打算取消提交,用到下面命令

    #只会保留源码(工作区),回退commit(本地仓库)与index(暂存区)到某个版本

    $ git reset <commit_id>

    #默认为 --mixed模式

    $ git reset --mixed <commit_id>

    #保留源码(工作区)和index(暂存区),只回退commit(本地仓库)到某个版本

    $ git reset --soft <commit_id>

    #源码(工作区)、commit(本地仓库)与index(暂存区)都回退到某个版本

    $ git reset --hard <commit_id>

    回退本地commit(已经push)

    对于已经把代码push到线上仓库,你回退本地代码其实也想同时回退线上代码,回滚到某个指定的版本,线上,线下代码保持一致.你要用到下面的命令

    $ git revert <commit_id>

    回退单个文件的历史版本

    #查看历史版本
    git log 1.txt
    
    #回退该文件到指定版本
    git reset [commit_id] 1.txt
    git checkout 1.txt
    
    #提交
    git commit -m "回退1.txt的历史版本"
  • 相关阅读:
    跳出iframe
    leetcode 225. Implement Stack using Queues
    leetcode 206. Reverse Linked List
    leetcode 205. Isomorphic Strings
    leetcode 203. Remove Linked List Elements
    leetcode 198. House Robber
    leetcode 190. Reverse Bits
    leetcode leetcode 783. Minimum Distance Between BST Nodes
    leetcode 202. Happy Number
    leetcode 389. Find the Difference
  • 原文地址:https://www.cnblogs.com/huhanhaha/p/9262076.html
Copyright © 2011-2022 走看看