Category: Git

  • git删除commit

    删除最近的一次 commit

    git reset --hard HEAD~1

    git rebase -i HEAD~1

    使用 git log 的时候看到的 sha1 的提交

    git reset --hard 

    如果不幸已经提交,则需要如下操作将提交还原

    git push origin HEAD --force

    将所有修改还原

    git reset --hard HEAD

    经过上面的操作, commit 被删掉了,你做的工作也废了

    如果你只是想要撤回提交,但并不想把工作废掉,可以使用 –soft

    git reset --soft HEAD~1

    我错删了一个文件并提交,现在需要将这次的提交恢复

    git revert c588349186b8dc3d074d64eca1408d2966a30cdc

    然后显示如下信息,我可以写下为什么要收回这次提交

    Revert "delete no use .vimrc"
    
    This reverts commit c588349186b8dc3d074d64eca1408d2966a30cdc.
    
    # Please enter the commit message for your changes. Lines starting
    # with '#' will be ignored, and an empty message aborts the commit.
    # On branch master
    # Your branch is ahead of 'origin/master' by 1 commit.
    #   (use "git push" to publish your local commits)
    #
    # Changes to be committed:
    #       new file:   ubuntu/home/jpuyy/.vimrc
    

    然后这就变成了一次新的提交,但是返回到了之前的版本.

    参考:
    http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git

  • gitignore使用方法

    .gitignore里写明了一些故意不想存在于版本库里的文件

    lib-cov
    *.seed
    *.log
    *.csv
    *.dat
    *.out
    *.pid
    *.gz
    
    pids
    logs
    results
    
    npm-debug.log
    .DS_Store
    node_modules
    .idea
    *.iml
    *.sqlite3
    
    

    参考:
    https://github.com/github/gitignore/blob/master/Node.gitignore
    https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore