Learning content source:
Liao Xuefeng Git Tutorial
Centralized and distributed
Centralized: centrally stored in a central server, must be networked
Distributed: Everyone on the computer is complete repository requires coordinated when you can push themselves to push to the recipient, or only the code needed to be able to pull down the sender.
Install Git
Baidu itself, this I have installed Git use of wsl-ubuntu learning
Create Repository
git init
Used to manage the current directory becomes git directory.
git add
Add files, git commit
submit files
Time Machine
git status
View modify the state
git diff
View modify
Version rollback
git log
View commit log, quit you may need to click q
git log --pretty=oneline
Single-line display log
HEAD
It represents the current version, HEAD^
represents the previous version, HEAD^^
represents the previous version, HEAD~100
represents more than 100 HEAD version.
git reset
You can fall back to version history. git reset --hard HEAD^
Back to the previous version. git reset --hard commit_id
Back to the specified id.
git reflog
You can view the history command.
Work area and staging area
Workspace: is the current directory git repository where, in addition to the .git repository.
Repository: which kept a lot of things,
The most important thing is called a stage (or called index) of the staging area , as well as the first branch of our Git automatically created master
, as well as pointing to master
a pointer called HEAD
.
Modify management
Git management is modified, git add
changes into the staging area inside the Stage, git commit
changes into the current branch.
Undoing Changes
git checkout --filename
You can be discarded modify the workspace!
No - it will become to switch to another branch!
git checkout either ,, can.
git reset HEAD <file>...
You can clear out the temporary files inside the area.
== git the RESET command == either rollback version, you can also modify the temporary area to fall back to the work area. When we use HEAD, represent the latest version.
git reset either ,, can.
Delete Files
After the file manager to delete files
git rm
You can delete files from the current repository inside, before ever commit files can be rolled back after being deleted. .
git checkout --
From inside the repository will be deleted file recovery.
Remote repository (one killer)
Built a gitee account, add ssh public key. OK
Adding a remote repository
git remote add origin https://gitee.com/dluff/learngit.git
#上面将添加一个名为origin的远程仓库
git push -u origin master
#将本地库的素有内容推送到远程仓库上
#把本地库的内容推送到远程, 用git push命令, 实际上是把当前分支master推送到远程。
#由于远程库是空的, 我们第一次推送master分支时, 加上了-u参数, Git不但会把本地的master分支内容推送的远程新的master分支, 还会把本地的master分支和远程的master分支关联起来, 在以后的推送或者拉取时就可以简化命令。
git push origin master
The latest modification of the local master branch pushed to GitHub.
Cloned from a remote repository
Remember git clone
it.
Branch Management
Prior to the merger, the branch should be invisible to others.
Founded in merging branches
git checkout -b dev
Create and switch to the dev branch.
Equivalent to git branch dev
+git checkout dev
git branch
Kayes to view the current status of the branch.
git merge
Per channel used to combine the development of the current branch.
git branch -d
To delete the branch.
Git encourage you to use the branch to complete a task, and then delete the merged branch, which is directly on the master branch and working effect is the same, but the process more secure.
Resolve conflicts
When Git does not automatically merge branches, we must first resolve the conflict. Post-conflict resolution, and then submit the merger is completed.
git log --graph
You can see branches merged graph.
Branch Management Strategy
First of all, master branch should be very stable, which is only used to release a new version, usually can not work on it;
Where does that work? Work in the dev branch, that is to say, dev branch is unstable, at some point, such as when the 1.0 version is released, then the dev branch into the master, release 1.0 version in the master branch;
You and your little friends and everyone on the dev branch to work, everyone has their own branch, from time to time to dev branch merge it.
Branch teamwork looks like this:
When you merge branches, plus the --no-ff parameters you can use normal mode merger, the combined history with branches, can see it once did merge, merge and fast forward to see it once did merge.