问题描述
我需要将所有的提交放在一个叫做初始快照的提交中,以便在github Repo中释放它,我知道为了做到这一点,我遵循
我的第一个问题是我想要与外部存储库共享它,并且这么说:
发生了什么,我想把所有的我提交一个单一的,如何做到这一点:
我也发现这个:
#切换到主分支并确保您是最新的。
git checkout master
git fetch#这可能是必要的(取决于你的git配置)来接收原产地/主人的更新
git pull
#合并特征分支到主分支。
git merge feature_branch
#将主分支重置为原始状态。
git reset origin / master
#Git现在将所有更改视为未分离的更改。
#我们可以将这些更改添加为一个提交。
#添加。还会添加未跟踪的文件。
git add --all
git commit
但没有任何反应:
$ git reset origin / master
$ git add --all
$ git commit -m初始快照
在分支主机
上你的分支是'origin / master'的最新版本。
没有提交,工作目录干净
最简单的方法是使用 rebase
命令。
想象一下你有这个存储库:
$> git log --oneline
af28aeb另一个测试
a680317尝试一下
d93792b编辑这两个文件
f23cdbd第二次提交添加b
6f456bc第一次提交添加一个
所以你已经用提交 af28aeb做了一些测试另一个测试
和 a680317尝试一些
。我们希望在 d93792b之后压缩它们以编辑这两个文件
以清理存储库。为此,该命令将会
git rebase -i d93792b
其中 -i
是指示以交互模式进入,并且 d93792b
是提交散列,我们希望吸收前一个。
$ b $注意:如果你想压缩第一个提交的所有提交,你必须使用
git rebase --root -i
这个命令会告诉你:
pick a680317尝试一下
pick af28aeb另一个测试
#Rebase d93792b..af28aeb到d93792b(2个TODO项目)
#
#命令:
#p,pick =使用提交
#r,reword =使用提交,但编辑提交消息
#e,edit =使用提交,但停止修改
#s,squash =使用提交,但融入前面的提交
#f,fixup = likesquash,但放弃这个c ommit的日志消息
#x,exec =运行命令(该行的其余部分)使用shell
#
#这些行可以重新排序;他们从上到下执行。
#
#如果你在这里删除一行,那么COMMIT将会丢失。
#
#但是,如果您删除了所有内容,那么rebase将被中止。
#
#注意空提交被注释掉
你必须告诉改变你想要做的事情。在这种情况下,我建议你重写第一次提交并压扁第二次,如下所示:
reword a680317尝试一下
squash af28aeb另一个测试
#将d93792b..af28aeb重新映射到d93792b(2个TODO项目)
#
#命令:
#p,pick =使用提交
#r reword =使用提交,但编辑提交消息
#e编辑=使用提交,但停止修改
#s,squash =使用提交,但融入以前的提交
#f,fixup = likesquash,但放弃这个提交的日志消息
#x,exec =运行命令(该行的其余部分)使用shell
#
#这些行可以重新排序;他们从上到下执行。
#
#如果你在这里删除一行,那么COMMIT将会丢失。
#
#但是,如果您删除了所有内容,那么rebase将被中止。
#
#注意空提交被注释掉
然后你的文本编辑
修复bug
#请输入提交信息为你的改变。用'#'开始
#的行将被忽略,并且一个空的消息将中止提交。
#
#日期:星期二7月28日08:40:04 2015 +0200
#
#rebase正在进行中;到d93792b
#您正在编辑提交,同时在'd93792b'上重新设定分支'master'。
#
#要提交的更改:
#新文件:c
#
现在您必须 git commit --amend
和 git rebase --continue
到完成这个过程。
您的资源库会显示如下:
$> git log --oneline
5f98806修复bug
d93792b编辑这两个文件
f23cdbd第二次提交添加b
6f456bc第一次提交添加一个
I need to put all my commits in a single one called initial snapshot, in order to release it in a github Repo, I know that for doing this I follow this
My first question is that I want to share it with a external repository and this say:
and what happens I want to put all my commits in a single one, how to do this:
I found also this:
# 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
but nothing happens:
$ 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
The easiest way to do that is by using rebase
command.
Imagine you have this repository:
$> git log --oneline
af28aeb Another test
a680317 Try something
d93792b Edit both files
f23cdbd Second commit add b
6f456bc First commit add a
So you have done some test with commits af28aeb Another test
and a680317 Try something
. We want to squash them after d93792b Edit both files
to clean the repository.
To do that the command will begit rebase -i d93792b
Where -i
is to indicate to enter in interactive mode and d93792b
is the commit hash where we want to absorbe the previous one.
Note: in case you want to squash all your commits like the first one, you have to use git rebase --root -i
That command will show you that:
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
You have to tell to rebase command what you want to do. In that case, I suggest you to reword the first commit and squash the second as follow:
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
Then your text edit will be opened to set the new commit message.
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
#
Now you have to git commit --amend
and git rebase --continue
to finish the process.
And your repository will show like this:
$> git log --oneline
5f98806 Fix bug
d93792b Edit both files
f23cdbd Second commit add b
6f456bc First commit add a
这篇关于在github的pull请求之前将所有提交压缩成一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!