gpt4 book ai didi

Git 保持远程分支(源)清洁

转载 作者:行者123 更新时间:2023-12-02 00:49:31 27 4
gpt4 key购买 nike

我正在按照 http://nvie.com/posts/a-successful-git-branching-model/ 的建议进行独立项目

我使用以下代码发布了我的代码的版本 1:

git checkout master
git merge --no-ff release-1.0

进入我的主分支,然后我发布:

git push

之后,我注意到远程分支(origin)拥有所有本地提交和分支,甚至是我认为私有(private)的分支。

我如何保留我的私有(private)本地历史,并在推送后仍然保持它们的来源“干净”?将代码的所有历史记录保存在我的本地存储库中似乎很有值(value),但如果我错了请纠正我!

如果在推送后无法保留单独的历史记录,我该如何清理我的本地历史记录而不丢失值得保留的信息?

最佳答案

每当你在 git 上推送一些东西时,你所有的历史到那个点和所有的提交都会被推送。

但是,如果您想稍微清理一下提交,最简单的方法是使用 git rebase -i 然后压缩您的提交。

假设您刚刚进行了一些小的提交,并且您希望从中进行一次较大的提交。

你的提交列表:

enter image description here

最后 4 次提交如果打包在一起会更快乐,所以让我们通过交互式 rebase 来做到这一点:

$ 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 将所有四个提交 merge 到列表中的第一个提交中。完成并保存后,另一个编辑器会 pop 以下内容:

# 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 允许您根据流程中涉及的其余提交修改新提交的消息。根据需要编辑消息,然后保存并退出。

Created commit 0fc4eea: Creating license file, and making jekyll self-aware.
4 files changed, 27 insertions(+), 30 deletions(-)
create mode 100644 LICENSE
Successfully rebased and updated refs/heads/master.

如果我们再回顾一下历史……

enter image description here

这是清理历史的最简单方法之一。

关于Git 保持远程分支(源)清洁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41103658/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com