Squash all your commits in one, before the transfer request on github

I need to put all my commits into one, which is called the initial snapshot, in order to release it in gythub Repo, I know that for this I follow this

My first question is that I want to share it with an external repository, and that says:

A word of caution: just to do this, does what the external repository hasn’t been pressed. If others have worked off you are about to remove, many conflicts can arise. Just don't rewrite your story if it has been shared with others.

and what happens, I want to put all my commits in one, how to do it:

I also found 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 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 
+8
git github
source share
1 answer

The easiest way to do this is to use the 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 did some test with commits af28aeb Another test and a680317 Try something . We want to deflate them after d93792b Edit both files to clear the repository.

For this, the command will be git rebase -i d93792b

Where -i indicates to enter interactive mode, and d93792b is the commit hash in which we want to use the previous one.

Note: if you want to deflate all your commits as the first, you should use git rebase --root -i

This 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 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 must tell the rebase command what you want to do. In this case, I suggest you rewrite the first commit and issue the second character as follows:

 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 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 editing will be open to set a 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 need git commit --amend and git rebase --continue to complete the process.

And your repository will look like this:

 $> git log --oneline 5f98806 Fix bug d93792b Edit both files f23cdbd Second commit add b 6f456bc First commit add a 
+18
source share

All Articles