I have been used to using SourceTree, there was something wrong with the last submission. Was a colleague with the command line to solve, suddenly feel the command line is still very useful, research.

1 introduction

Free version control tool, much more needless to say.

1.1 Basic Structure

  • The workspace
  • The staging area
  • repository
  • The remote repository

2 operation

2.1 the staging area

Git add adds the file to the staging area.

Add multiple files

git add [file1][file2] 
Copy the code

Adding folders

git add [dir]  
Copy the code

Add all files

git add .
Copy the code

2.1 Code Submission

Submit staging area to local warehouse

git commit -m [message]
Copy the code

Submits the specified file to the local repository

git commit [file1][file2] -m [message]
Copy the code

Commit the changes since the last commit to the local repository

git commit -a 
Copy the code

2.1 branch

Lists all local branches

git branch
Copy the code

List all remote branches

git branch -r 
Copy the code

List all branches (local and remote)

git branch -a 
Copy the code

Create a new branch (and stay in the current branch)

git branch [branch-name]
Copy the code

Create a new branch and switch to the new branch

git checkout -b [branch-name]
Copy the code

Creates a new branch and establishes a relationship with the specified remote branch

git branch --track[branch-name][remote-branch]
Copy the code

Switch to the specified branch and update the workspace

git checkout [branch-name]
Copy the code

Switch to the previous branch

git checkout -
Copy the code

Merges the specified branch into the current branch

git merge [branch-name]
Copy the code

Select a COMMIT. Merge into the current branch

git cherry-pick [commit]
Copy the code

Delete the branch

git branch -d [branch-name]
Copy the code

Delete remote branches – permissions required

git push orgin --delete [branch-name]
git branch -dr [rremote/ branch]
Copy the code

2.3 log

View the changed files

git status 
Copy the code

View the historical version of the current branch

git log
Copy the code

Search submission History

git log -s [keyword]
Copy the code

Shows the past five commits

git log -5 --pretty --oneline 
Copy the code

Shows the difference between staging area and workspace

git diff
Copy the code

Shows how much code was written today

git diff --shortstat "@{0 day ago}"
Copy the code

Displays the most recent commits

git reflog
Copy the code

2.4 Remote Synchronization

Download all changes to the remote repository

git fetch [remote]
Copy the code

Display all remote warehouses

git remote -v 
Copy the code

Displays information about a remote repository

git remote show [remote]
Copy the code

Add a remote repository

git remote add [shortname][url]
Copy the code

Pull code, and merge with the local

git pull [remote][branch]
Copy the code

Upload code to remote

git push [remote][branch] 
Copy the code

Force current branch to local (generally not allowed)

git push [remote] --force
Copy the code

Push all branches to the remote repository

git push [remote] --all 
Copy the code

2.5 to cancel

Restores the specified file from the staging area to the workspace

git checkout [file]
Copy the code

Restore the specified file of a COMMIT to the workspace

git chrckout [commit][file]
Copy the code

Restores all files from the staging area to the workspace

git checkout .
Copy the code

Resets the specified file in the staging area, consistent with the last COMMIT

git reset [file]
Copy the code

Reset the staging area and workspace as the last COMMIT

git reset --hard
Copy the code

Reset the pointer to the current branch to specify COMMIT, and reset the staging area, but leave the workspace unchanged

git reset --hard[commit]
Copy the code

Reset the head of the current branch to specify Commmit, as well as reset the staging area and workspace, consistent with specifying commit

git reset --keep [commit]
Copy the code

Create a COMMIT, but leave the staging area and workspace unchanged

git revert commit[commit]
Copy the code