Git reset

Some times we made many commit during PR , we want to combine them to one commit

We can see, I create 4 commits totally.

Git reset and rebase_git

1 backup the branch to remember the commit ID , in case that you did something wrong , you can roll-back.

$ git branch APPSOL-121312_local

Git reset and rebase_git_02

2 git branch -v . check the commit ID , the new branch has the same ID (b103a.....)

Git reset and rebase_git_03

3 git reset --soft commit ID( this commit ID is the one before your change, please check the first picture, 819f7 is checkout from master branch).

This command make all of your change combine together, and re-build a new commit ID.

Git reset and rebase_git_04

4 git status and git add ** and git diff --cached to see the change.

Git reset and rebase_git_05

5 git commit -m " massage"

Git reset and rebase_git_06

6 git push --force . (you must use --force) , other wise ,it will ask you to pull firstly. that will lead to conflict.

Git reset and rebase_git_07

Q : Why the command is : git ci , git lg ?

add this file's info to your file . PATH is ~/.gitconfig . Modify the email and name to yourself.

GIT Rebase :

1 backup the branch to remember the commit ID , in case that you did something wrong , you can roll-back.

`git branch yourBranch_local`


2 checkout to master branch to pull the latest code

Git reset and rebase_git_08

Git reset and rebase_git_09

3 checkout to target branch to reset code.

Git reset and rebase_git_10

4 backup the branch again to remember the commit ID ,in case that you did something wrong or meet conflict, you can roll-back.

5 rebase

To see all the code change you did

`git diff --cached `


before rebase , you should commit it.

`git commit -m " APPSOL-**** info "`


rebase :

git rebase master

Git reset and rebase_git_11

to push the code.

`git push --force`