Create a new code base

$Git init [url] $Git clone $Git init [url]Copy the code

Second, the configuration

Git’s Settings file is.gitconfig, which can be in the user home directory (global configuration) or in the project directory (project configuration).

$Git config [--global] $Git config [--global] $Git config [--global  "[name]" $ git config [--global] user.email "[email address]"Copy the code

Add/delete files

$git add [file1] [file2]... $git add [dir] $git add. $git add. $git add -p $git rm [file1] [file2] $git mv [file-original] [file-renamed]Copy the code

4. Code submission

$git commit [file1] [file2] $git commit [file1] [file2] $git commit -v $git commit -v $git commit -v $git commit -- amend-m [message] # amend the last commit, $git commit --amend [file1] [file2]...Copy the code

Five, the branch

$git branch -r $git branch -a $git branch [branch-name] $git checkout -b [branch] Commit $git branch [branch] [commit] $git branch --track [branch] [remote-branch] $git checkout [branch-name] $git checkout - $git branch --set-upstream [branch] [remote-branch] $git merge [branch] $git cherry-pick [commit] $git branch -d [branch-name] $git push origin --delete [branch-name] $git branch -dr [remote/branch] $git branch -dr [remote/branch]Copy the code
Git branch -- set-uppage-to =origin/ develop_chenCopy the code

Six, labels,

$git tag [tag] $git tag [commit] # Delete local tag $git tag $git show [tag] # $git push [remote] [tag] $git checkout -b [branch] [tag]Copy the code

7. Check information

$git status_log $git status_log $git status_log $git status_log $git status_log $git log -s [keyword] # $git log [tag] HEAD --pretty=format:%s # $git log [tag] HEAD --grep feature # --follow [file] $git whatchanged [file] # diff $git log -p [file --pretty --oneline # display all submitted users $git shortlog -sn = $git list = $git list = $git list = $git list = $git list $git diff [first-branch] $git diff [first-branch] $git diff [first-branch] $git diff --shortstat "@{0 day ago}" $git show [commit]# $git show --name-only [commit] $git show [commit]:[filename] $git reflog $git rebase [branch]Copy the code

8. Remote synchronization

$git remote $git remote $git remote $git remote $git remote $git remote add [shortname] [url] $git remote add [shortname] $git pull [remote] [branch] $git push [remote] [branch] $git push [remote] --all $git push [remote] --allCopy the code

Nine, cancellation

$git checkout [commit] [file] $git checkout [file $git reset [file] $git reset [commit] # reset the HEAD of the branch to commit. $git reset --hard [commit] # $git reset --keep [commit] # create a new commit to undo the specified commit $git Revert [commit] # Remove the uncommitted changes temporarily and move on to $git Stash $git Stash pop laterCopy the code

User name operation:

To view the user name:

git config user.name
Copy the code

View user email:

git config user.email
Copy the code

Modify command (modify user name) :

Git config --global user.name "Your_username"Copy the code

Modify user email addresses:

git config --global user.email "Your_email"
Copy the code

ignore

$ git update-index --assume-unchanged /path/to/file
Copy the code

Cancel to ignore

$ git update-index --no-assume-unchanged /path/to/file
Copy the code

Merge two branches (Merge two branches)

1. Merge development branch code into master

Git checkout dev/git checkout master git checkout dev/git checkout master # Push code to masterCopy the code

2. Synchronize master code to the development branch

Git checkout master git pull git checkout dev Git merge master git pull origin devCopy the code

3. Generate a distributable zip package

$ git archive
Copy the code