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.

pramod m
  • 39
  • 3

2 Answers2

3

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

git reset --soft "HEAD^"
git commit --amend
evgpisarchik
  • 452
  • 5
  • 9
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.

Community
  • 1
  • 1
Naveen Dennis
  • 1,223
  • 3
  • 24
  • 39