2

I'm beginner in GIT. I did some changes in my working project and created the the test branch using

git checkout -b 'test' 

I committed my changes twice.

git add . git commit -m "first commit" git push --set-upstream origin test 

Again I did some changes and committed changes

git add . git commit -m "second commit" git push --set-upstream origin test 

Now I created pull request . What exactly want is, I have two commits now. When I merge into master branch, I dont want see those two commit messages, I want to merge those messages "first commit" and "second commit" into one message and merge into master branch.

I tried rebase and rest commands. May be I'm using in wrong way. Can any one help me out this.

0

2 Answers 2

3

if you want to merge two last commits into one with a given name

git reset --soft "HEAD^" git commit --amend 
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks you.. after git commit.. Do I need to push the branch again ?
Yes, if you need to update your source code on github
Make sure that the last commits on github are yours and use git push --set-upstream origin test --force
the error happens because you try to rename commits that are already pushed to github
Good, be careful with --force option.If you push using it you'll get exactly the same commits on github as you have locally
|
0

Since you want to merge the two commits into a new branch as a single commit, you can use this answer.

Assuming you were in your own topic branch. If you want to merge the last 2 commits into one and look like a hero, branch off the commit just before you made the last two commits.

git checkout -b temp_branch HEAD^2

Then squash commit the other branch in this new branch:

git merge branch_with_two_commits --squash

That will bring in the changes but not commit them. So just commit them and you're done.

git commit -m "my message"

Now you can merge this new topic branch back into your main branch.

If you just want to merge the two commits into one in your current directory before pushing the code, then use this answer.

If there are multiple commits, you can use git rebase -i to squash two commits into one.

If there are only two commits you want to merge, and they are the "most recent two", the following commands can be used to combine the two commits into one:

git reset --soft "HEAD^"

git commit --amend

Safe to say that it is a duplicate but I wanted you to have links to the answer you are looking for.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.