Git foundation uses North pointing


Software is like sex: it’s better when it’s free. —— Linus Torvalds

Previous information – O –


The first thing to be clear is the workflow of GIT. When you use git, you use three different areas to manage your code.
1.Workspace: These are the files you are currently writing code, specifically the project you are currently editing.
2.Cache (index): is a temporary area to save your temporary changes.
3.Warehouse area (head): the area you last submitted to.
Git foundation uses North pointing
General process: (work area) code → add code to (buffer area) → submit to warehouse area (head) → push to remote warehouse

Basic use

Init initialization

When we want to use git to manage the project, use:

$ git init

Relevant initialization operations will be carried out automatically, and hidden data will be created in the project. git folder, which contains relevant configuration information.

Add cache operation

If you want git to track the file, the file will arriveBufferYes, it is equivalent to copying a copy. Use the command:

#Add file to cache
$git add [filename 1] [filename 2]
#Add folder to cache
$git add [folder]
#Add all files to cache
$ git add .

After executing the change command, GIT will track the changes of your file. Usegit statusCommand, you can see the status of the file.

#View file status
$ git status
#View concise status information short
$ git status -s

Of course, you can also delete the cache

#Stops tracking the specified file, which remains in the workspace
$ git rm --cached [file]

Commit warehouse area operation

usegit commitThe command will add the operation of the cache to the warehouse area,Submit information should be added for each submission

#Submit files from the cache to the warehouse
#Then the VM editor opens and asks for the submission information
$ git commit
#Simplify, submit and add submission information
$git commit - M 'submit information'
#Skip adding to the cache and directly submit the modifications after the last submission
#All tracked files are temporarily stored and submitted together
$ git cmmit -a

When a file has been submitted, to submit the record of deleting the file, use$git RM [file name]Command, the corresponding files in the workspace will be deleted, and the deleted records will be added to the cache, and then you cancommit

Remote operation

Git operations are basically carried out locally, but if you need multi person assistance, saving / open source to gitee or GitHub requires remote operation.

#Add a remote warehouse without its name
#When you create a new warehouse in GitHub, it will let you run this command
#Associate your local warehouse with a remote warehouse. It can add multiple warehouses
$git remote add [remote warehouse name] [url]
$ git remote add origin
#View all remote warehouses
$ git remote -v
#After there is a remote warehouse, upload the new branch
$git push - u [remote warehouse] [branch]
$ git push -u origin master
#Upload local branch
$git push [remote warehouse name] [branch name]
$ git push origin master
#Direct push to remote warehouse
$ git push
#Violence is pushed to a remote warehouse, ignoring the conflict
$ git push --force
#Download the code of the remote warehouse to the local
#This operation does not change the local warehouse
#Instead, there will be a branch of a remote warehouse locally, such as origin / master
$git fetch [remote warehouse]
#Pull the remote warehouse to the local and merge it into the local operation
#Its essence is to merge the local branch and remote branch after fetch
$git pull [remote warehouse] [branch]

fallback action

Git is used not only for the convenience of version management, but also for emergencies, so it is also possible to fallback code.
Note: before performing the fallback operation, remember to submit the contents of the current workspace

#Undo the operation of the specified file in the workspace and undo it to the state of add
$git restore [file]
#Fallback cached files to workspace
$git checkout [file]
#Fallback all files in the cache to the workspace
$ git checkout .
#Back the workspace to the last commit
$ git reset --hard
#Fallback the head of the current branch to the specified commit
#Reset the staging area and workspace at the same time, which is consistent with the specified commit
$ git reset --hard [commit]

Advanced operation

Branch operation

Branches are like various varieties derived from the same variety. Each branch can have different variation directions. However, in git, branches are controllable. You can add, merge and delete.
Git foundation uses North pointing

#View all current branches
$ git branch
#New branch
$git Branch [branch name]
$ git branch dev
#And change branches
$git checkout [branch]
$ git checkout master
#Create a new branch and switch to the new branch
$git checkout - B [branch]
$ git checkout -b feature_x
#Delete the branch. If there is no content that has not been merged, it cannot be deleted
#The current branch cannot be deleted. If you want to delete it, you need to switch branches
$git branch - D [branch]
#Force delete branch
$git branch - D [branch]
#Merge the current branch with the specified branch
$git merge [branch]
$ git merge dev

Other operations

#View all submitted records
$ git log
#Save uncommitted changes temporarily
$ git stash
#Temporarily restore uncommitted saved changes
$ git stash pop