• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • git rebase, squash and others

    Blogs20152015-01-05


    1. git rebase squash

    Suppose I have 3 git commits today for same `jira` story. I resolve the story and want to git push. Before that, I want to `git rebase` to `squash` the commits into One, for better view of `git diff/show` out of the details:

    //1. to squash 3 commits into 1
    $ git rebase -i HEAD~3
    
    //2. in the opened vim, change 2nd and afterwards picks to squash
    pick 01d1124 start processing story abc...
    squash 6340aaa using `advanced rest client`
    squash ebfd367 change `request.js`
    
    //3. continue add commits in the second vim,save and quit vim.
    
    //4. the rebase success, then:
    $ git push origin branch --force
    
    //5. now 3 commits disappears, only the merged one is displayed
    $ git log | head

    This way can dramatic release the pain for daily improvements and make version control clean and simplify.

    2. git rebase and others

    Some summary about rebasing different branches. WebStorm->Changes tab is a great help.

    //1.checkout a branch first,then:
    git rebase other_branch
    
    //repeat the following steps:
    //using WebStorm or vim to fix conflicts
    git checkout <commit-hash> path/to/file
    git add .
    git rebase --continue
    //Is there a better way to do the rebase?
    
    //2. git revert to previous branch
    git reset --hard <commit-hash> //^HEAD, HEAD~1,...
    
    //3. git revert previous file
    //(a). review the changes
    git diff <commit-hash> path/to/file
    //(b). revert a specific file:
    git reset <commit-hash> path/to/file //?
    git checkout <commit-hash> path/to/file
    
    //4. git stash
    //(a). keep all the changes to stash instead of add/commit
    git stash
    //(b). apply the stash into current codes.
    git stash list
    git stash pop
    git stash apply
    git stash show
    3. Others
    • change `hostname` in MacBook Air - sudo scutil —set HostName favorite-hostname
    • monitoring port number - lsof | grep 35729
      netstat -an | grep 8080