我需要将所有提交放在一个名为初始快照的提交中,以便在github Repo中释放它,我知道为了这样做我遵循这个
我的第一个问题是我想与外部存储库共享它,这说:
需要注意的是:只在尚未推送到外部存储库的提交中执行此操作.如果其他人的工作基于您要删除的提交,则可能会发生许多冲突.如果已经与他人共享,请不要重写您的历史记录.
我想把所有提交放在一个单一的提交中会发生什么,如何做到这一点:
我发现了这个:
# Switch to the master branch and make sure you are up to date.
git checkout master
git fetch # this may be necessary (depending on your git config) to receive updates on origin/master
git pull
# Merge the feature branch into the master branch.
git merge feature_branch
# Reset the master branch to origin's state.
git reset origin/master
# Git now considers all changes as unstaged changes.
# We can add these changes as one commit.
# Adding . will also add untracked files.
git add --all
git commit
Run Code Online (Sandbox Code Playgroud)
但没有任何反应:
$ git reset origin/master
$ git add --all
$ git commit -m "initial snapshot"
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
Enr*_*iMR 20
最简单的方法是使用rebase
命令.
想象一下,你有这个存储库:
$> git log --oneline
af28aeb Another test
a680317 Try something
d93792b Edit both files
f23cdbd Second commit add b
6f456bc First commit add a
Run Code Online (Sandbox Code Playgroud)
所以你已经做了一些提交af28aeb Another test
和测试a680317 Try something
.我们想在d93792b Edit both files
清理存储库之后压缩它们.
要做到这一点,命令将是
git rebase -i d93792b
在哪里-i
指示进入交互模式并且d93792b
是我们想要吸收前一个的提交哈希.
注意:如果您想要像第一个那样压缩所有提交,则必须使用 git rebase --root -i
该命令将向您显示:
pick a680317 Try something
pick af28aeb Another test
# Rebase d93792b..af28aeb onto d93792b ( 2 TODO item(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Run Code Online (Sandbox Code Playgroud)
你必须告诉rebase命令你想做什么.在这种情况下,我建议你改写第一次提交并压缩第二次提交,如下所示:
reword a680317 Try something
squash af28aeb Another test
# Rebase d93792b..af28aeb onto d93792b ( 2 TODO item(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Run Code Online (Sandbox Code Playgroud)
然后将打开您的文本编辑以设置新的提交消息.
Fix bug
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Tue Jul 28 08:40:04 2015 +0200
#
# rebase in progress; onto d93792b
# You are currently editing a commit while rebasing branch 'master' on 'd93792b'.
#
# Changes to be committed:
# new file: c
#
Run Code Online (Sandbox Code Playgroud)
现在,你必须git commit --amend
和git rebase --continue
完成过程.
您的存储库将显示如下:
$> git log --oneline
5f98806 Fix bug
d93792b Edit both files
f23cdbd Second commit add b
6f456bc First commit add a
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18440 次 |
最近记录: |