Git保持远程分支(源)干净
我正在做一个单独的项目,听从来自 我使用以下方法发布了代码的第1版:Git保持远程分支(源)干净,git,Git,我正在做一个单独的项目,听从来自 我使用以下方法发布了代码的第1版: git checkout master git merge --no-ff release-1.0 # This is a combination of 4 commits. # The first commit's message is: Adding license # This is the 2nd commit message: Moving license into its own file # This i
git checkout master
git merge --no-ff release-1.0
# This is a combination of 4 commits.
# The first commit's message is:
Adding license
# This is the 2nd commit message:
Moving license into its own file
# This is the 3rd commit message:
Jekyll has become self-aware.
# This is the 4th commit message:
Changed the tagline in the binary, too.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: LICENSE
# modified: README.textile
# modified: Rakefile
# modified: bin/jekyll
#
在我的主分支机构中,我发布了:
git push
之后,我注意到远程分支(origin)拥有所有本地提交和分支,甚至是我认为是私有的
我如何保持我的私人地方历史,并在推后仍然保持它们的起源“干净”?在我的本地回购协议中保留代码的所有历史记录似乎很有价值,但如果我错了,请纠正我
如果推送后无法保留单独的历史记录,我如何清理本地历史记录而不丢失值得保留的信息?提交的完整历史记录是提交的一部分,因此如果推送提交,您将在远程上看到完全相同的内容
要在推送之前清理和整理您的历史记录,您可以查看。每当您在git上推送某个内容时,您的所有历史记录以及所有提交都会随之推送 但是,如果您想说清理一下提交,最简单的方法是使用
git-rebase-i
然后挤压提交
假设您刚刚做了一些小的提交,您希望从中做出一个更大的提交
您的提交列表:
如果将最后4个提交打包在一起,则会更快乐,因此让我们通过交互式重定基来实现这一点:
$ git rebase -i HEAD~4
pick 01d1124 Adding license
pick 6340aaa Moving license into its own file
pick ebfd367 Jekyll has become self-aware.
pick 30e0ccb Changed the tagline in the binary, too.
# Rebase 60709da..30e0ccb onto 60709da
#
# Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
在这个屏幕上有很多选项可供选择,但现在我们将把所有内容压缩成一个提交。因此,将文件的前四行更改为该行将实现以下目的:
pick 01d1124 Adding license
squash 6340aaa Moving license into its own file
squash ebfd367 Jekyll has become self-aware.
squash 30e0ccb Changed the tagline in the binary, too.
基本上,这告诉Git将所有四个提交合并到列表中的第一个提交中。完成并保存后,会弹出另一个编辑器,其中包含以下内容:
git checkout master
git merge --no-ff release-1.0
# This is a combination of 4 commits.
# The first commit's message is:
Adding license
# This is the 2nd commit message:
Moving license into its own file
# This is the 3rd commit message:
Jekyll has become self-aware.
# This is the 4th commit message:
Changed the tagline in the binary, too.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: LICENSE
# modified: README.textile
# modified: Rakefile
# modified: bin/jekyll
#
如果我们再看看历史
这是清理一点历史的最简单方法之一 如前所述,您需要压缩您的提交。有一种简单的方法–使用以下工具将分支与私有历史合并:
git merge --squash <dev-branch>
git合并--squash
这将创建一个新的提交,其中包含与
开发分支
相同的数据,但不包含该分支的单个提交列表。在推送时,重新基础答案是使工作提交不可见的好方法
但是,您还希望在本地回购协议中保留您的工作承诺记录
要做到这一点,最简单的方法是在本地回购协议上设立一个开发分支机构,
并为推送创建一个单独的分支。在推送单独的分支之前重新设置其基础。挤压提交时,是否会失去对这些提交内容的访问权限?似乎在提交之后,甚至本地提交也会被删除(默认情况下)。这是否意味着,如果我的代码只存在于这些即将被压缩的提交中,我应该在压缩之前采取措施对它们进行备份?git-rebase-i非常有用,尤其是在commit-msg管理中!谢谢挤压提交时,不会丢失对提交的访问。Rebase只是将所有内容重放到新的压缩提交中。如果我能帮点忙,我很高兴。如果我能帮助你,请投票或接受答案。谢谢。关于重播的最后一个问题:使用上面的示例,如果我在commit 30e0ccb中引入了一段新代码“也更改了二进制中的标记行”。然后我在commit ebfd367中删除了相同的代码“Jekyll已经自我感知”。一旦我挤压了上面示例中的提交,91天后我将如何检索该代码?(大概是为了了解我是如何让杰基尔意识到自己的!)投票通过并接受了!如果我让master“干净”作为推动分支,“发展”作为本地回购的发展分支。当我在签出master时发布“gitpush”时,是否只会推送master,还是会同时推送development?(我所有的实验都表明是后者,所以我可能做错了!)您可以这样指定:git push origin master这是一个简单的总结:有更多的推送选项。请参阅推送时的在线文档。