惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

生产力 – Ed_'s Blog

数据模型初探 – yywr's Blog 简易个人数据备份方案 – yywr's Blog DTR工作法 – yywr's Blog
GIT Basic usage – yywr's Blog
yywr · 2019-03-31 · via 生产力 – Ed_'s Blog

Creation a repository

Use command CD path\directory to enter the directory to be used as the repository
git init

After a few files has been created in the repository directory, we need to add the changes to this repository
1. Add changes to the stage(index)
git add Readme.md
git add BaseUsage.md
2. Committing changes to the repostiory. The option -m is very important. So we konw what we changed
git commit -m "Creation the readme.md file and the baseusage.md"

View the status of repository

git status

We must know status of repository before we can continue our work. If we have changed some files, we’d better know what we changed in the files
git diff

Now, we konw that the changes are correct. we can add the file to the stage and commit to repository.
git add BaseUsage.md
git commit -m "Add some contents in BaseUsage.md . View the staus of repository"

View commit log and roll-back

Before I write this line I committed a wrong version of this file the version named “Wrong information”,then rolled it back. What did I do?

First, we have to know how many commits are in this repository.
git log
or
git log --oneline
We can see the last commit on the top, and be tagged “HEAD -> master”. The older commits are in below.

The tag “HEAD” means this commit is the current version.

Now, let’s roll-back commit.
git reset --hard HEAD^
This command will roll-back one version commit. If you want to roll-back two version or more, you can use this:
git reset --hard HEAD^^
git reset --hard HEAD^^^^
(Let’s ignore the option “–hard” for now)

If you check the status of this repository. You can see that the last previous commit was discarded.

Recall the roll-back

We rolled back the commit earlier, but we don’t want to do that now. So what should we do?

First we should know the serial number of commit that was discarded before.
git reflog
This command can print the changing log.

Now we can find the serial number of the commit that we discarded before. Then recall the roll-back.
git reset --hard "serial number"

About Working tree

We have an branch “Master”(repository),our changes were commited to “Master”. When we edit or create files, the files all save in working tree, which is the folder we see on the computer.

About Stage

After we change files in this folder, we can see the diffrence between working tree and “master”. If we affirm the changes, we can add the changes to stage.

About repository

Does add the changes to Stage can make repository be latest. No. Stage and repository are different place.

There are three place: Working Tree, Stage and repository.

We change files in working tree . Then add changes from working tree to to Stage . Last, We commit changes from stage to repository.

The command git diff is to compare difference between working tree and stage. when we add changes from working tree to stage , the difference disappear

How do we konw the difference between working tree and repository? This command can tell us.
git diff HEAD
or
git diff HEAD -- "file"

Undo changes

We can undo changes manual in working tree
Or use this command git checkout -- "file" to discard chages in working tree.

If the changes are added to stage we also can unstage
git reset HEAD "file"
This command meaning that the changes roll-back from stage to working tree. Then we can undo changes in working tree.

About how to undo changes in repository? Do you remember roll-back commit?
But remember that roll-back commit will change working tree.

Delete file

That will make a difference if we delete a file from file explorer. So what shall we do?

If the change is correct, we have to remove the file in repository and commit.
git rm "file"
git commit -m "Remove "file" "

If we would like to restore file that was deleted in working tree before, what shall we do?
Remember undo command git checkout "file"?
This command will restore changes in working tree from repository.