__Git learning

Learning content source:

  1. Liao Xuefeng Git tutorial
  2. Code learning little cloud application

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 initUsed to manage the current directory becomes git directory.

git addAdd files, git commitsubmit files

Time Machine

git statusView modify the state

git diffView modify

Version rollback

git logView commit log, quit you may need to click q

git log --pretty=onelineSingle-line display log

HEADIt represents the current version, HEAD^represents the previous version, HEAD^^represents the previous version, HEAD~100represents more than 100 HEAD version.

git resetYou can fall back to version history. git reset --hard HEAD^Back to the previous version. git reset --hard commit_idBack to the specified id.

git reflogYou 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 mastera pointer called HEAD.

Modify management

Git management is modified, git addchanges into the staging area inside the Stage, git commitchanges into the current branch.

Undoing Changes

git checkout --filenameYou 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 rmYou 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 masterThe latest modification of the local master branch pushed to GitHub.

Cloned from a remote repository

Remember git cloneit.

Branch Management

Prior to the merger, the branch should be invisible to others.

Founded in merging branches

git checkout -b devCreate and switch to the dev branch.

Equivalent to git branch dev+git checkout dev

git branchKayes to view the current status of the branch.

git mergePer channel used to combine the development of the current branch.

git branch -dTo 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 --graphYou 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:

image-20200315235526787

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.

Bug branch

Guess you like

Origin www.cnblogs.com/dluff/p/12501240.html