git tip

  1. Remove local changes.  There is 3 types of local change file
    • Type 1: Staged tracked files
    • Type 2: Unstaged tracked files
    • Type 3: Unstaged untraced files.
    • git checkout .    : Remove type 2 file
    • git clean -f         : Remove type 3 file
    • git reset –hard : remove type 1 and type 2
    • git stash -u        : remove  type 1, 2, and 3
    • git reset –soft   : change type 1 to change 2
  2. Undo pushed change
    • git revert HEAD, or git revert {SHA}.( this will create a new commit which you can push and undo the previous change),
  3. Cherry pick a change from one git to another for merge
    • git fetch $git-1-url $branch && git cherry-pick $SHA  (then resolve merge conflicts, git add ,  e.g.,
    • git fetch git@github.zhukeyao/spark.git master && git cherry-pick {SHA} Resolve merge conflicts, git add
  4. create a patch and applied to another branch
    • git diff {SHA1} {SHA2} > patch.diff
    • git checkout target-branch
    • git apply patch.diff
  5. Add all modified file
    • git ls-files –modified  | xargs git add

git tip

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s