Git - only push up the most recent commit to github

前端 未结 3 733
臣服心动
臣服心动 2020-12-08 07:17

On my local git repo I\'ve got many commits, which include \'secret\' connection strings :-)

I don\'t want this history on github when I push it there.

Essen

3条回答
  •  一生所求
    2020-12-08 07:53

    You can branch your current work, rewind the master, then cherry-pick the latest commit back to the master:

    git branch secret
    git reset --hard HEAD~3
    git cherry-pick secret
    

    In pictures,

        A--B--C--D--E (master)
    

    after git branch secret:

        A--B--C--D--E (master, secret)
    

    after git reset --hard HEAD~3:

        A--B (master)
            \
             C--D--E (secret)
    

    after git cherry-pick secret:

        A--B--E' (master)
            \
             C--D--E (secret)
    

    Finally, if you git checkout secret; git rebase master, you can get:

        A--B--E' (master)
               \
                C--D (secret)
    

提交回复
热议问题