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

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

Git – Ed_'s Blog

暂无文章

GIT Basic usage – yywr's Blog
yywr · 2019-03-31 · via Git – 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.