Commit a file to a Different Branch Without Checkout

前端 未结 10 2064
南方客
南方客 2020-12-05 09:55

Is it possible to commit a file in a git branch with out checking out that branch? If so how?

Essentially I want to be able to save a file in my github pages branch

10条回答
  •  情深已故
    2020-12-05 10:15

    This is how I do it:

    if I've acidentally committed, roll back one commit:

    git reset --soft 'HEAD^'
    

    add the files you want to add

    git add .
    

    create a new temporary branch:

    git checkout -b oops-temp
    

    commit your changes:

    git commit -m "message about this commit"
    

    checkout the branch you meant to check out:

    git checkout realbranch
    

    merge the old branch:

    git merge oops-temp
    

    delete the old branch:

    git branch -D oops-temp
    

提交回复
热议问题