Common git commands
1. Basic commands
Git branch view local branches
Git branch-r view remote branch
Git checkout xxx switch Branch
Git pull origin master // synchronize from remote to local, master or branch name
Git pull origin xxx
Git checkout-B xxx: Create a branch of xxx
Git checkout-B local branch name remote branch name
Git branch-D xxx Delete local branch
Git status view status
Git add file add to local server cache
Git checkout -- file is rolled back from the Local Machine
Git add path1 path2... add and modify the file path to the stage state.
Git commit submit local server
Git log
Git diff cmt1 cmt2 -- stat View File changes of cmt1 and cmt2
Git checkout -- filename removes modifications to local files,
Git stash removes all local updates
Git log -- committer xiaojin. lh
Git reset -- hard commit-id: roll back to commit-id. Remove all committed commit after commit-id.
2. Pull remote Branch
1) First, clone and obtain the remote trunk.
Git clone git@gitlab.abcde-inc.com: mysql-engine/alisql. git empty directory
2) view remote branches
Git branch-r
3). Create a local branch based on the remote Branch
Git checkout-B local branch name remote branch name
4) Pull the latest remote Branch
Git pull origin feature_encryption_issue1
5). Pull a remote tag, such as pulling the 4.11.2 version of the remote rocksdb.
Git checkout-B 4.11.2 v4.11.2
3. Push to remote
Git push <Remote Host Name> <local branch name>: <remote branch name>
Git push origin xxx: xxx push local branches to remote
Git push origin xxx. If the remote branch is omitted, the local xxx branch is pushed to the remote xxx branch. If the branch does not exist, it is created.
Git push origin xxx: xxx -- dry-run simulate push
Git push orgin: xxx indicates pushing an empty Branch to a remote branch, which is equivalent to deleting a remote branch.
It is equivalent:
Git push origin -- delete xxx
4. Merge branch master
1) switch to the master branch (the target branch to be merged, which is the master Branch)
2) merge branches
Git merge feature_encryption_issue1, (name of the branch to be merged, here is feature_encryption_issue1)
3). Push to remote
Git push origin master
For example, if you are developing feature_xxx and the master has been updated at this time, you need to merge the latest master:
4). Update the master in the feature_xxx branch.
Git checkout feature_xxx
Git merge master
5) Merge the master node into a branch feature_xxx
Git checkout master
Git merge feature_xxx
5. Steps for submitting a Merge Request
1). Delete remote Branch
Git push origin: xxx_branch // Delete remote xxx Branch
2). Pull the master
Git clone git@gitlab.abcde-inc.com: mysql-engine/mysql. git xxx_branch
3) create a new branch
Git checkout-B xxx_branch
4) Merge diff files
Git apply xxx. diff
5). Local submission
Git commit-am "[feature] comment"
6). Push to remote Branch
Git push origin xxx_remote_branch
7). Submit locally. Use -- amend // commit to follow the previous version number.
Git commit -- amend [local commit]
8). Push to remote, use -- force
Git push origin xxx: xxx -- force [push to remote]
6. Generate a patch and merge the patches.
1). Basic commands
Git diff old-commit current-commit> xxx. patch generation patch
Git apply xxx. patch applies a patch, transaction operation, all succeeded or all failed.
Git apply-R xxx. patch restores a commit. xxx. patch is the change content.
Git apply -- check patch before applying the patch, you can run the command -- check to check whether there is a conflict with the patch.
Git apply patch -- if there is a conflict with reject, you can use -- reject to check where the conflict exists and modify it.
2) Pull a trunk and apply the patch
Git clone git@gitlab.abcde-inc.com: mysql-engine/alisql. git
Patch-p1 <*. diff
3). commit
4). push to remote.