@w1024020103
2017-02-05T09:42:16.000000Z
字数 1439
阅读 759
CS61B
Let's update our HELLO.txt. Here I used a text editor called vim to add some text to the file, and a tool called cat to show the file to you in the screenshot. You can use any text editor of your choice. If you've never used vim, use a different text editor (it's hard to use for beginners). If you get stuck in vim, try googling to see how to get out of it. Getting stuck in vim is a rite of passage.
If we want to save the change we made in git, first we'll have to stage it. Stage it with the add command. Then, suppose we decide we no longer like the change we made, and we don't want to save it in Git. Unstage the file with the reset command. Important: The reset command does NOT change the actual HELLO.txt file. In terms of our panorama analogy, it only deletes the picture we took of this file!
Problem: I didn't get the expected result when I used Sublime to add one line to the text and then git add HELLO.txt
.
Weird thing is, I restart Git Bash and things went right.
Then, I typed git reset HEAD HELLO.txt
, not much reply, but when I then typed git reset
, it showed what was expected to be shown. Weird.
Now suppose we dislike the changes we made and want to return the file to its state the last time we committed it -- that is, bgitefore we added the extra lines. Discard your changes to HELLO.txt since your first commit with the checkout command. Here, instead of specifiying a commit ID, we'll use the -- command, which uses the most recent commit by default.
When you changed one line of the text file and haven't added yet, you can cancel the change using git checkout -- HELLO.txt
. For instance, I typed subl HELLO.TXT
to open my file and deleted the line I previously added.
resources I found helpful:
Git – 恢复撤销篇
git checkout 命令撤销修改
撤销修改