During the development process, new requirements and bugs will be constantly discovered. At this time, a good software is required to manage the project. Git provides a complete version management function to store and track the modification history of directories (folders) and files. It is a necessary tool for software developers and the infrastructure of software companies. Git supports configuration management activities of software companies, tracks development and maintenance activities for multiple versions, and releases software in a timely manner.
Install git:
Click Download git. After the installation is successful, the "Git Bash" option after installation is displayed on the desktop.
Create a folder demo, right-click it, and choose git Bash here from the shortcut menu.
Generate the key:
Enter ssh-keygen-t rsa-c "[email protected] *. com" in the Command box and press enter three times in a row. The key fingerprint is displayed, indicating that the generation is successful.
In the c: \ Users \ your \. Ssh path, id_rsa and id_rsa.pub are displayed. The previous file is the private key and the other is the public key. Generally, the Public Key Server is authenticated.
Some git commands are introduced as follows:
Create a repository:
Git clone git: // github.com/clone remote Repository
Git init initializes the local repository
Global Configuration:
Git config-global user. Name <Name> specifies the name of the submitter.
Git config-global user. Email <email> sets the email address of the submitter.
Git config-global core. Editor <editor> sets the default text editor.
Git config-Global merge. Tool <tool> sets a time difference analysis tool for resolving merge conflicts
Git config-list check existing configuration information
Submit modification content
Git Add. Add all modified files
Git add <File> Add the specified file
Git MV <old> <New> file rename
Git Rm <File> delete a file
Git Rm-cached <File> stops the trace file but does not delete it.
Git commit-M <File> submit the specified file
Git commit-m "commit message" submit all updated files
Git commit-amend modification last commit
Git commit-C head-a-amend addition submission (no new submission history records will be generated)
View submission history
Git log to view the submission history
Git log-P <File> View the submission history of the specified file
Git blame <File> View the submission history of a specified file in the list
Gitk to view the current branch history
Gitk <branch> View the historical records of a branch
Gitk -- all view the historical records of all branches
Git branch-V Final commit of each branch
Git status to view the current status
Git diff
Undo operation
Git reset-hard head undo all changes to uncommitted files in the working directory
Git checkout head <file1> <file2> undo the modification of the specified uncommitted File
Git checkout head. Undo All files
Git revert <commit> undo the specified commit
Branch and label
Git branch displays all local branches
Git checkout <branch/tagname> switch to the specified branch or tag
Git branch <New-branch> creates a new branch
Git branch-D <branch> Delete local branch
Git tag list all local tags
Git tag <tagname> Create a tag based on the latest commit
Git tag-D <tagname> Delete tag
Merger and Derivation
Git merge <branch> merge the specified branch to the current Branch
Git rebase <branch> extends the specified branch to the current Branch
Remote Operation
Git remote-V view remote version Library Information
Git remote show <remote> view the information of the specified remote version Library
Git remote add <remote> <URL> Add a remote Repository
Git fetch <remote> Get code from remote database
Git pull <remote> <branch> download code and merge it quickly
Git push <remote> <branch> upload code and merge it quickly
Git push <remote>: <branch>/<tagname> delete a remote branch or tag
Git push-tags Upload All tags
When you are developing a warehouse with others, you can create a warehouse by yourself as follows:
Git branch-B 'Branch-name' create branch-name
Git checkout-B 'branch-name' create a branch and switch to the new branch
Git commit submits changes
Git push submitted to remote
Switch the GIT checkout master branch to the master Branch
Git pull updates master branch code
Git merge -- no-FF 'Branch-name' merge your branches to the master Branch
When two people modify a file at the same time, conflicts may occur when submitting or merging branches. solution:
Git stash places the modified content in the cache
Git pull updates Code submitted by others
Git stash POP releases the code in the cache
Check the file status in git status. If a file conflict is prompted, open the corresponding file and modify the file, and then add the file in git.
Delete Branch (no one is allowed to operate on the current Branch before deleting the Branch ):
Git branch-D branch name Delete local branch
Git push Origin -- delete branch name Delete remote repository Branch
Execute git fetch origin to update the latest branch after the branch is deleted.
View your modifications:
View git diff before submission
View after submitting git show
Restore deleted files:
Git LS-files -- deleted
Git checkout -- file-name restore File
View File Operation history:
Git log-P filename
Note: Before submitting your own code, you must update git pull to the latest code to avoid conflict.
Git configuration file:
In the command line, enter VI ~ /. Gitconfig to enter the GIT configuration file. The following configuration is mainly a simplified command, add (I, paste) to the configuration file, save and exit (: WQ ).
[Alias]
CO = checkout
Ci = commit
BR = Branch
St = Status
Unstage = reset head --
Last = Log-1 Head
Mg = merge -- no-FF
Glog = log -- pretty = oneline -- Graph
DF = difftool
SH = stash
PL = pull -- rebase
PH = Push
SP = stash pop
Lg = log -- color -- graph -- pretty = format: '% cred % H % creset-% C (yellow) % d % creset % S % cgreen (% Cr) % C (bold blue) <% an> % creset'
Rv = revert -- soft head ^
[Color]
Ui = true
[Format]
Pretty = oneline
Git shortcut:
Insert: Paste
CTRL + F: view the next page
CTRL + B: view the previous page
I: Enter the editing mode.
ESC: exit the editing mode.
: WQ save and exit
Q: Exit reading mode
Summary:
Git is a powerful version control software that allows you to easily manage your own projects. The following is a URL that describes how git works:
Git-Concise Guide: http://rogerdudler.github.io/git-guide/index.zh.html
Graphical git: http://marklodato.github.io/visual-git-guide/index-zh-cn.html