Are there any Git command to combine all our ugly commits together to one?
When I write the code in local, sometimes I commit the code that isn't clean yet, or, with an ugly message as temporary revision.
However, when I want my code to merge with the others, I would like the only final snapshot that the other can see, (hidden the revisions that look ugly)
Ex.
I fork 0 to my local repository, I make change and test and commit with unclean code
0->1->2->3->4->5->6 (Final code)
when the others pull the code, is it possible to make other see only final state? and not see the tree from 1..5
I want users will see like
0------------------->6
One way I can think of is making a patch file, but it not good enough if there is some file have to be deleted or create.
git
add a comment |
When I write the code in local, sometimes I commit the code that isn't clean yet, or, with an ugly message as temporary revision.
However, when I want my code to merge with the others, I would like the only final snapshot that the other can see, (hidden the revisions that look ugly)
Ex.
I fork 0 to my local repository, I make change and test and commit with unclean code
0->1->2->3->4->5->6 (Final code)
when the others pull the code, is it possible to make other see only final state? and not see the tree from 1..5
I want users will see like
0------------------->6
One way I can think of is making a patch file, but it not good enough if there is some file have to be deleted or create.
git
stackoverflow.com/questions/5308816/how-to-use-git-merge-squash
– Gerry
Sep 7 '11 at 10:26
add a comment |
When I write the code in local, sometimes I commit the code that isn't clean yet, or, with an ugly message as temporary revision.
However, when I want my code to merge with the others, I would like the only final snapshot that the other can see, (hidden the revisions that look ugly)
Ex.
I fork 0 to my local repository, I make change and test and commit with unclean code
0->1->2->3->4->5->6 (Final code)
when the others pull the code, is it possible to make other see only final state? and not see the tree from 1..5
I want users will see like
0------------------->6
One way I can think of is making a patch file, but it not good enough if there is some file have to be deleted or create.
git
When I write the code in local, sometimes I commit the code that isn't clean yet, or, with an ugly message as temporary revision.
However, when I want my code to merge with the others, I would like the only final snapshot that the other can see, (hidden the revisions that look ugly)
Ex.
I fork 0 to my local repository, I make change and test and commit with unclean code
0->1->2->3->4->5->6 (Final code)
when the others pull the code, is it possible to make other see only final state? and not see the tree from 1..5
I want users will see like
0------------------->6
One way I can think of is making a patch file, but it not good enough if there is some file have to be deleted or create.
git
git
edited May 18 '18 at 5:02
jiexishede
1,06421635
1,06421635
asked Sep 7 '11 at 10:20
scalopusscalopus
1,35621129
1,35621129
stackoverflow.com/questions/5308816/how-to-use-git-merge-squash
– Gerry
Sep 7 '11 at 10:26
add a comment |
stackoverflow.com/questions/5308816/how-to-use-git-merge-squash
– Gerry
Sep 7 '11 at 10:26
stackoverflow.com/questions/5308816/how-to-use-git-merge-squash
– Gerry
Sep 7 '11 at 10:26
stackoverflow.com/questions/5308816/how-to-use-git-merge-squash
– Gerry
Sep 7 '11 at 10:26
add a comment |
5 Answers
5
active
oldest
votes
You can use reset --soft
to squash multiple commits into a single new clean commit. With your branch at the final code with no staged changes you can do:
git reset --soft <sha1-of-0>
git commit
When git commit
prompts, give a clear commit message describing the complete changes being introduced.
add a comment |
The most flexible way to do this is to do an interactive rebase to squash together or amend your commits. You need to be careful not to rewrite any history that's already public, however. For example, if you're working on the master
branch, and you want to rewrite and linearize all your commits that aren't in origin/master
(which typically means the work that you haven't pushed yet) you can do:
git rebase -i origin/master
That will launch a text editor where each commit you have that isn't in origin/master is shown, from oldest to newest. If you want want to combine any commit with the previous one, you can just change the start of the line from pick
to squash
. Or, if you want to amend that commit somehow, you can change pick
to edit
.
Using interactive rebase is the most flexible way of doing what you ask for, and it's a very useful tool to get to know, but in the exact situation you describe, it's probably overkill. First, check that the output of git status
is clean, so that you're sure that your staging area represents the same state as HEAD
. You can then just do a "soft reset" back to 0
, which resets HEAD
to that commit, but leaves your working tree and index (i.e. the staging area) intact. If you then do a commit, your index will be used to create a new commit with the same state as 6
, but with 0
as a parent. i.e.
git status # Check that your status is clean
git reset --soft 0
git commit -m 'Work that is totally flawless'
add a comment |
Yes, use git rebase -i
, and squash the commits. Check this for more info and some examples.
add a comment |
Assuming you haven't already pushed your commits to the remote then there are several ways to do this.
One option is to use
git rebase -i
which gives you the interactive rebase editor. You can then mark all the commits except the last as 'squash'
add a comment |
Git squash merge is designed for this purpose. The way you would do this is to create a branch, make all your changes, and then merge back using squash merge.
How to use git merge --squash?
However, this isn't usually recommended because you will lose history this way.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7332260%2fare-there-any-git-command-to-combine-all-our-ugly-commits-together-to-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use reset --soft
to squash multiple commits into a single new clean commit. With your branch at the final code with no staged changes you can do:
git reset --soft <sha1-of-0>
git commit
When git commit
prompts, give a clear commit message describing the complete changes being introduced.
add a comment |
You can use reset --soft
to squash multiple commits into a single new clean commit. With your branch at the final code with no staged changes you can do:
git reset --soft <sha1-of-0>
git commit
When git commit
prompts, give a clear commit message describing the complete changes being introduced.
add a comment |
You can use reset --soft
to squash multiple commits into a single new clean commit. With your branch at the final code with no staged changes you can do:
git reset --soft <sha1-of-0>
git commit
When git commit
prompts, give a clear commit message describing the complete changes being introduced.
You can use reset --soft
to squash multiple commits into a single new clean commit. With your branch at the final code with no staged changes you can do:
git reset --soft <sha1-of-0>
git commit
When git commit
prompts, give a clear commit message describing the complete changes being introduced.
answered Sep 7 '11 at 10:23
CB BaileyCB Bailey
514k78555611
514k78555611
add a comment |
add a comment |
The most flexible way to do this is to do an interactive rebase to squash together or amend your commits. You need to be careful not to rewrite any history that's already public, however. For example, if you're working on the master
branch, and you want to rewrite and linearize all your commits that aren't in origin/master
(which typically means the work that you haven't pushed yet) you can do:
git rebase -i origin/master
That will launch a text editor where each commit you have that isn't in origin/master is shown, from oldest to newest. If you want want to combine any commit with the previous one, you can just change the start of the line from pick
to squash
. Or, if you want to amend that commit somehow, you can change pick
to edit
.
Using interactive rebase is the most flexible way of doing what you ask for, and it's a very useful tool to get to know, but in the exact situation you describe, it's probably overkill. First, check that the output of git status
is clean, so that you're sure that your staging area represents the same state as HEAD
. You can then just do a "soft reset" back to 0
, which resets HEAD
to that commit, but leaves your working tree and index (i.e. the staging area) intact. If you then do a commit, your index will be used to create a new commit with the same state as 6
, but with 0
as a parent. i.e.
git status # Check that your status is clean
git reset --soft 0
git commit -m 'Work that is totally flawless'
add a comment |
The most flexible way to do this is to do an interactive rebase to squash together or amend your commits. You need to be careful not to rewrite any history that's already public, however. For example, if you're working on the master
branch, and you want to rewrite and linearize all your commits that aren't in origin/master
(which typically means the work that you haven't pushed yet) you can do:
git rebase -i origin/master
That will launch a text editor where each commit you have that isn't in origin/master is shown, from oldest to newest. If you want want to combine any commit with the previous one, you can just change the start of the line from pick
to squash
. Or, if you want to amend that commit somehow, you can change pick
to edit
.
Using interactive rebase is the most flexible way of doing what you ask for, and it's a very useful tool to get to know, but in the exact situation you describe, it's probably overkill. First, check that the output of git status
is clean, so that you're sure that your staging area represents the same state as HEAD
. You can then just do a "soft reset" back to 0
, which resets HEAD
to that commit, but leaves your working tree and index (i.e. the staging area) intact. If you then do a commit, your index will be used to create a new commit with the same state as 6
, but with 0
as a parent. i.e.
git status # Check that your status is clean
git reset --soft 0
git commit -m 'Work that is totally flawless'
add a comment |
The most flexible way to do this is to do an interactive rebase to squash together or amend your commits. You need to be careful not to rewrite any history that's already public, however. For example, if you're working on the master
branch, and you want to rewrite and linearize all your commits that aren't in origin/master
(which typically means the work that you haven't pushed yet) you can do:
git rebase -i origin/master
That will launch a text editor where each commit you have that isn't in origin/master is shown, from oldest to newest. If you want want to combine any commit with the previous one, you can just change the start of the line from pick
to squash
. Or, if you want to amend that commit somehow, you can change pick
to edit
.
Using interactive rebase is the most flexible way of doing what you ask for, and it's a very useful tool to get to know, but in the exact situation you describe, it's probably overkill. First, check that the output of git status
is clean, so that you're sure that your staging area represents the same state as HEAD
. You can then just do a "soft reset" back to 0
, which resets HEAD
to that commit, but leaves your working tree and index (i.e. the staging area) intact. If you then do a commit, your index will be used to create a new commit with the same state as 6
, but with 0
as a parent. i.e.
git status # Check that your status is clean
git reset --soft 0
git commit -m 'Work that is totally flawless'
The most flexible way to do this is to do an interactive rebase to squash together or amend your commits. You need to be careful not to rewrite any history that's already public, however. For example, if you're working on the master
branch, and you want to rewrite and linearize all your commits that aren't in origin/master
(which typically means the work that you haven't pushed yet) you can do:
git rebase -i origin/master
That will launch a text editor where each commit you have that isn't in origin/master is shown, from oldest to newest. If you want want to combine any commit with the previous one, you can just change the start of the line from pick
to squash
. Or, if you want to amend that commit somehow, you can change pick
to edit
.
Using interactive rebase is the most flexible way of doing what you ask for, and it's a very useful tool to get to know, but in the exact situation you describe, it's probably overkill. First, check that the output of git status
is clean, so that you're sure that your staging area represents the same state as HEAD
. You can then just do a "soft reset" back to 0
, which resets HEAD
to that commit, but leaves your working tree and index (i.e. the staging area) intact. If you then do a commit, your index will be used to create a new commit with the same state as 6
, but with 0
as a parent. i.e.
git status # Check that your status is clean
git reset --soft 0
git commit -m 'Work that is totally flawless'
answered Sep 7 '11 at 10:29
Mark LongairMark Longair
290k60354299
290k60354299
add a comment |
add a comment |
Yes, use git rebase -i
, and squash the commits. Check this for more info and some examples.
add a comment |
Yes, use git rebase -i
, and squash the commits. Check this for more info and some examples.
add a comment |
Yes, use git rebase -i
, and squash the commits. Check this for more info and some examples.
Yes, use git rebase -i
, and squash the commits. Check this for more info and some examples.
answered Sep 7 '11 at 10:22
GeoGeo
45.9k91287466
45.9k91287466
add a comment |
add a comment |
Assuming you haven't already pushed your commits to the remote then there are several ways to do this.
One option is to use
git rebase -i
which gives you the interactive rebase editor. You can then mark all the commits except the last as 'squash'
add a comment |
Assuming you haven't already pushed your commits to the remote then there are several ways to do this.
One option is to use
git rebase -i
which gives you the interactive rebase editor. You can then mark all the commits except the last as 'squash'
add a comment |
Assuming you haven't already pushed your commits to the remote then there are several ways to do this.
One option is to use
git rebase -i
which gives you the interactive rebase editor. You can then mark all the commits except the last as 'squash'
Assuming you haven't already pushed your commits to the remote then there are several ways to do this.
One option is to use
git rebase -i
which gives you the interactive rebase editor. You can then mark all the commits except the last as 'squash'
edited Sep 7 '11 at 17:08
answered Sep 7 '11 at 10:27
BenBtgBenBtg
5161518
5161518
add a comment |
add a comment |
Git squash merge is designed for this purpose. The way you would do this is to create a branch, make all your changes, and then merge back using squash merge.
How to use git merge --squash?
However, this isn't usually recommended because you will lose history this way.
add a comment |
Git squash merge is designed for this purpose. The way you would do this is to create a branch, make all your changes, and then merge back using squash merge.
How to use git merge --squash?
However, this isn't usually recommended because you will lose history this way.
add a comment |
Git squash merge is designed for this purpose. The way you would do this is to create a branch, make all your changes, and then merge back using squash merge.
How to use git merge --squash?
However, this isn't usually recommended because you will lose history this way.
Git squash merge is designed for this purpose. The way you would do this is to create a branch, make all your changes, and then merge back using squash merge.
How to use git merge --squash?
However, this isn't usually recommended because you will lose history this way.
answered Nov 21 '18 at 5:18


Melbourne DeveloperMelbourne Developer
1,7541235
1,7541235
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7332260%2fare-there-any-git-command-to-combine-all-our-ugly-commits-together-to-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/5308816/how-to-use-git-merge-squash
– Gerry
Sep 7 '11 at 10:26