• When extracting files from git stash (you can see here for more details) in Powershell, you may encounter a strange error which says error: unknown switch `e'.
    It is caused by the {} character in Powershell: these braces are parsed unexpectedly. Use ` symbol to escape them: git checkout stash@{0} -- /path/to/your/file
  • Rollback to any commit that you have ever committed:

    git reflog
    git reset HEAD@{index}
  • Update your commit RIGHT after it has been committed:

    git add .
    git commit --amend --no-edit # the commit will now contains what you have added
  • Change the message of my last commit: git commit --amend
  • move a just-committed one to a new branch
    If you committed to master/main:

    # create a new branch from the current state of master
    git branch some-new-branch-name
    # remove the last commit from the master branch
    git reset HEAD~ --hard
    git checkout some-new-branch-name

    If you committed to another branch:

    git checkout name-of-the-correct-branch
    # grab the last commit to master
    git cherry-pick master
    # delete it from master
    git checkout master
    git reset HEAD~ --hard


标签: git, powershell, shell