Git:删除文件

好了,现在我们应该会一些更加基础的git的操作,比如说删除一个文件,我可能创建的时候一下子就创建了很多个文件,现在我想要删除一个,那我们就可以用命令:"git rm blablabla" like this:

Let's take this for example,we want to delete the third file:

 And now we can see that the third file is removed!

 Actually this happens not only in the repository,but also in the working copy.So this is really an awesome instruction which brings convenience.

 

And we now are going to commit something:

 

Before we commit,we need to know why we should do that.

 

Type in "git status" and you'll know why:

 

 So we need to commit:

 What if we accidentally delete the file that doesn't have to be deleted?At this time we surely want our file back.And you'll see how cool this git tool is.

Holy f... the F-word!The git tutorial didn't show us how to get it back!Okay,guys,I'll be back and complete this hard stuff once the tutorial gets updated.

Anyway we now really know what we are supposed to do to remove a file,which is really easy.

So now we should learn how to rename a file.Actually it's pretty easy if you just do it through your desktop,but it could be more confusing with git.Let's see how that works:

First we rename the first file to "home" through the desktop:

 By the way,don't change its contents.

 

And this is what happened:

 

 Apparently,git thinks that it should first delete the original file and then add a new one.

Now let's do something even crazier:

 Oh I think you see it!Git thought that you actually renamed the file!

So we can commit now:

You just commit it and I'm not going to show you how to do it.

But it's really confusing and it's not handy,right?

Now we are going to do it in another way,which is really easier!

Now go ahead with the second file,actually the second file is exactly how it's called that way.

 That should do it.

Now we check what happened:

 So "mv" is pretty much the same thing as renaming it,and you'll have to admit it,so admit it.

It's amazing after realizing how it works!And here comes moving the file to another folder,you'll know it tomorrow.(And don't forget to commit the changes!)

Waking up in a snowing morning!I'm back!

So now I create a folder named "LoveNotes" and I want to add a file to the folder.

 

 

Basically we want to move the file "pudding.txt" to the folder "LoveNotes" and give it a new name!Let's see how we can do that!

 

Same instruction!

 

 

 We go back to the parent folder and see what happened:

 

 

Hahaha!That file vanished!But once we double-click the folder "LoveNotes" and:

 

 

 

This is what we saw!The file was renamed!How amazing!

 

Let's go back to git and type in "git status" and see what happens!

 

 

 This is another proof for what I said.

You can just do that to make everything easier!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2022-02-06 15:58  EvanTheBoy  阅读(311)  评论(0)    收藏  举报