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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

生产力 – 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.