只会将最近的提交提交给github

只会将最近的提交提交给github

本文介绍了Git - 只会将最近的提交提交给github的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地git仓库中,我有很多提交,其中包括'秘密'连接字符串: - )

我不希望这个历史记录在github上时我把它推到那里。

基本上我想推动我拥有的所有东西,但是想要摆脱很多历史。



也许我会更好地在所有我的开发者的分支中运行,然后在提交之前将它们合并回主服务器,那么主服务器的历史记录就会成为我想要的提交。



我尝试过运行rebase:

 git rebase -i HEAD〜3 

返回3个提交,然后我可以删除一个提交。



然而,遇到自动樱桃挑选失败,它得到相当复杂。

任何想法都不胜感激......如果这太难了,可以重新开始历史并重新开始: - )

$ b $你可以分支你当前的工作,倒回主,然后樱桃选择最新的提交给master:

  git分支机密
git reset --hard HEAD〜3
git樱桃挑选秘密

在图片中,

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

after git branch secret

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

之后> git reset --hard HEAD〜3

 
A - B(主)
\
C - D - E(秘密)

之后> git cherry-pick secret

 
A - B - E'(主)
\
C - D - E(秘密)

最后,如果你 git checkout secret; git rebase master ,你可以得到:

 
A - B - E'(master)
\
C - D(秘密)


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.

Essentially I want to push everything I have, but want to get rid of a whole lot of history.

Perhaps I would be better running in a branch for all my dev, then just merging back to master before committing... then the history for master will just be the commit I want.

I've tried running rebase:

git rebase –i HEAD~3

That went back 3 commits, and then I could delete a commit.

However ran into auto cherry-pick failed, and it got quite complex.

Any thoughts greatly appreciated... no big deal to can the history and start again if this gets too hard :-)

解决方案

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)

这篇关于Git - 只会将最近的提交提交给github的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:43