- alias
alias gitlog='git log --all --decorate --oneline --graph'
- stash
helps you stash your work away and clear your working directory. Then when you checkout it will not carry over the new code with you.
refergit stash # add them to the stash git pull # do update git stash pop # get the changes back into your working tree
- reset
reset works with refs, on your working directory and the index, without touching any commit objects (or other objects)git reset --hard git reset
- rebase
Rebasing a branch in Git is a way to move the entirety of a branch to another point in the tree and rewrite previously made commit objects./o-----o---o--o-----o--------- branch --o-o--A--o---o---o---o----o--o-o-o--- master after rebase /o-----o---o--o-----o------ branch --o-o--A--o---o---o---o----o--o-o-o master
- rebase interactive
git rebase -i HEAD~5 git rebase --continue drop/squash...
-
squash
a way to rewrite your commit history - rebase and merge
rebase branch b1 on to current master, means take branch b1(from commit 7f3b00e to commit 872a38f) and rebase (put them on top of) master (60dc441).
$ git log --oneline --graph --all
* 60dc441 (HEAD -> master) adding master.txt file
| * 872a38f (b1) adding b1 file
|/
* 7f3b00e adding file 2
* df2fb7a adding file 1
$ git checkout b1
Switched to branch 'b1'
# Rebase (b1 which is current branch) on master
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: adding b1 file
# The result
$ git log --oneline --graph --all
* 5372c8f (HEAD -> b1) adding b1 file
* 60dc441 (master) adding master.txt file
* 7f3b00e adding file 2
* df2fb7a adding file 1
$ git checkout master
Switched to branch 'master'
# the current history, where b1 is based on master
$ git log --oneline --graph --all
* 5372c8f (b1) adding b1 file
* 60dc441 (HEAD -> master) adding master.txt file
* 7f3b00e adding file 2
* df2fb7a adding file 1
# Performing the merge, notice the "fast-forward" message
$ git merge b1
Updating 60dc441..5372c8f
Fast-forward
b1.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 b1.txt
# The Result
$ git log --oneline --graph --all
* 5372c8f (HEAD -> master, b1) adding b1 file
* 60dc441 adding master.txt file
* 7f3b00e adding file 2
* df2fb7a adding file 1
- merge
git checkout feature git merge master /o--o--o--o---------- feature --o--o--o--o--master------ /
This will create a new “Merge commit” in the feature branch that holds the history of both branches.
<<<<<<< HEAD current ======= need to be merged >>>>>>> updated_address
- another branch
git checkout -b new_local_branch SHA git pull upstream/remote_branch
- cherrypick
if you want to make a pr to branch A by cherry-picking a commit from a branch B
```
# to get the latest branches
git pull –rebase upstream branchA
git checkout branchA
git cherry-pick
# to push the commit
git push origin branchA
- resolve conflicts
0. git fetch origin master # run in the local personal branch
1. git rebase origin/master # in local personal branch , rebase your branch on top of the latest master branch
2. edit files to resolve conflicts
«< HEAD –> latest change from master
====
xxx -> my local changes
```
- git add
- git rebase –continue
- git log
- git push -f origin
- cherry pick
refer
git checkout master
git cherry-pick xxx
Object
All the information needed to represent the history of a project is stored in files referenced by a 40-digit “object name” that looks something like this:
6ff87c4664981e4397625791c8ea3bbb5f2279a3
Every object consists of three things - a type, a size and content. The size is simply the size of the contents, the contents depend on what type of object it is, and there are four different types of objects: “blob”, “tree”, “commit”, and “tag”.
A “blob” is used to store file data - it is generally a file.
A “tree” is basically like a directory - it references a bunch of other trees and/or blobs (i.e. files and sub-directories)
A “commit” points to a single tree, marking it as what the project looked like at a certain point in time. It contains meta-information about that point in time, such as a timestamp, the author of the changes since the last commit, a pointer to the previous commit(s), etc.
A “tag” is a way to mark a specific commit as special in some way. It is normally used to tag certain commits as specific releases or something along those lines.
git show <SHA>
git ls-tree <SHA>
Multiple accounts
refer
ssh-keygen -t rsa -C "email@work_mail.com" -f "id_rsa_work_user1"
ssh-add ~/.ssh/id_rsa_work_user1
~/.ssh/config
## config
git config --global url."ssh://git@xxx".insteadOf "https://xxx"
# Work account-1
Host github.com-work_user1
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work_user1