I. Creating a version Library
① initializing a git repository: git init
② add files to git repository: 1.git add<file>; 2.git Commit
Two. Time Machine Shuttle
① View workspace Status, whether the file has been modified: git status
② See what's Changed: Git diff
1. Version fallback
①head: Current Version
②head^: Last version
③ Location Version:git reset --hard commit_id
④git log: Before the shuttle, git log
you can view the commit history in order to determine which version to fallback to
⑤git Reflog: To return to the future, use the git reflog
view command history to determine which version to return to in the future.
2. Workspaces and Staging Area
① Workspace: The directory that you can see on your computer, such as my learngit
folder is a workspace
② repository: The workspace has a hidden directory .git
, not a workspace, but a git repository.
③ Staging Area: There are a lot of things in Git's repository, the most important of which is the staging area called stage (or index).
The first step is to add the file git add
, in effect, to add the file to the staging area;
The second step is to commit the git commit
changes, in effect, to commit all the contents of the staging area to the current branch.
3. Management changes
① each modification, if not add to staging area, will not be added to the commit
4. Undo Changes
①git Checkout--File: Discard workspace Modifications
②git Reset HEAD file: Undo Staging Area changes and re-return to workspace
5. deleting files
①git RM: Deleting files from the repository
Three. Remote Warehouse 1. Adding remote libraries
① Associating a remote library: Git remote add origin [email protected]:p Ath/repo-name.git
② for the first time after associating all the contents of the Master branch:git push -u origin master
③ thereafter, after each local commit, you can use the command to push the git push origin master
latest changes whenever necessary
PS: Since the remote library is empty, when we first push the master
branch, with the -u
parameters, Git will not only master
push the local branch content of the remote new master
branch, but also the local branch and the master
Remote master
Branch Association. You can simplify the command at a later push or pull.
2. Cloning from a remote library
① to clone a warehouse, you must first know the address of the warehouse and then use the git clone
command clone
②git supports multiple protocols, including https
, but with the fastest ssh
supported native git
protocols
Four. Branch management 1. Create and Merge Branches
① View branch: Git branch
② Creating a branch: Git branch<name>
③ Switch branch: Git cheakout<name>
④ Create + Switch branch: git cheakout-b <name>
⑤ Merge a branch to the current branch: Git merge<name>
⑥ Deleting a branch: git branch-d <name>
2. Conflict resolution
① View Branch merge diagram: git log-graph
Eg:git log--graph--pretty =oneline--abbrev-commit
3. Branch Management Policy
① add--no-ff parameter when merging branches: Normal mode merge, merged history branch, disable Fast Forward
Eg:git log--no-ff-m "merge with No--ff" Dev
4.Bug Branch
①git Stash: Hide the current job site to fix bugs
②git Stash pop: Restore work site while deleting stash content
5.Feature Branch
① develop a new feature, it is best to create a new branch;
② If you want to discard a branch that has not been merged, you can remove it by git branch -D <name>
forcibly deleting the
6. Multi-person collaboration
①git remote-v: Viewing remote library information
②git Push Origin branch-name: Push branch from local
③git Pull: Fetching a remote new commit when push fails
④git checkout-b branch-name origin/branch-name: branches corresponding to local and remote branches (the names of local and remote branches are best consistent)
⑤git Branch--set-upstream branch-name Origin/branch-name: Establishing Association of local and remote branches
Five. Label Management 1. Create a label
①git tag <name>: Create a new label (the default is head, you can also specify a commit ID)
②git tag-a <tagname>-M "Blablabla ...": Label information can be specified
③git tag-s <tagname>-M "Blablabla ...": Can be signed with PGP information
④git tag: View all tags
2. Operation label
①git push Origin <tagname>: Push a local label
②git Push Origin--tags: Push all the local labels that have been pushed off
③git tag-d <tagname>: Delete a local label
④git push origin:refs/tags/<tagname>: Delete a remote label
Six. Using GitHub
① on GitHub, can fork open source warehouse;
② own read and write access to the warehouse after the fork;
③ can push pull request to the official repository to contribute code.
Seven. Custom Git1. Ignoring special files
① you need to write when ignoring certain files .gitignore
;
2. Configure aliases
①我们只需要敲一行命令,告诉Git,以后st
就表示status
:
git config --global alias.st status
eg
$ git config --global alias.co checkout$ git config --global alias.ci commit$ git config --global alias.br branch
$ git config --global alias.unstage ‘reset HEAD‘
$ git config --global alias.last ‘log -1‘
alias.lg "log --color --graph --pretty=format:‘%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset‘ --abbrev-commit"
3. Build a git server
GitHub is a remote repository that hosts open source code for free. But for some source code such as the life of the business company, neither want to open source code, but also reluctant to pay for the protection of GitHub, then you can only build a git server as a private warehouse use.
For example, Volkswagen reviews code.dianpingoa.com
"Git tutorial-Liaoche" Learning notes