My Git Pearls

Set up git

  • User name: git config --global user.name "my name"
  • Email: git config --global user.email "email addr"
  • Init a repo: git init

 

Branching

  • List branches: git branch -a
  • Work on a branch: git checkout <branch name>
  • Checkout a remote branch: git checkout -b <new branch>  <start point>
        e.g. git checkout -b stable-1.3 remotes/origin/stable-1.3


  • Create a new local branch: git branch [branch_name]
  • Delete a local branch: git branch -d [branch_name]
  • Delete a remote branch: git push [remote] [:branch_name]
        e.g. git push origin :newfeature  That will delete the newfeature branch on theorigin remote, but you’ll still need to delete the branch locally withgit branch -d newfeature.

  • Publish a local branch to remote:
        e.g.  git push [remote] [local_branch_name]:[remote_branch_name]


Remote repositories

  • list remote repos: git remote

 

Synchronization

  • Pull a repo: git pull <repo>
  • Push to a repo: git push <repo> <refspec>
        e.g. git push github stable-1.3


Undo

  • If you've messed up the working tree, but haven't yet committedyour mistake, you can return the entire working tree to the lastcommitted state with:
    $ git reset --hard HEAD
    $ git reset --hard HEAD~1


Cherry-picking
  • If you would like to cherry-pick a commit from a branch, use command as follows, in which -x suggests git to append a line that says "(cherry picked from commit ...)"...
    $ git cherry-pick -x <commit_id>
  • If a cherry-picking fails, try abort all temporary actions by:
    $ git cherry-pick --abort
  • If you would like to cherry-pick a range of commits, try:
    $ git cherry-pick [old_commit]..[new_commit]
  • or, go though each of them by command as follows and then cherry-pick it one by one:
    $ git rev-list --reverse b..f | xargs -n 1 git cherry-pick

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值