What is the difference between git checkout and git reset?

git log-- oneline-- all

then what"s the difference between git checkout and git reset?

found some information but didn"t understand it. I hope God can explain it in popular language. Tweet


background knowledge:

manipulate the file under git, which has three places to "store" the file

  1. Workspace
  2. staging area
  3. version library

as long as you have modified the file, the file automatically appears in the workspace. When you have finished modifying it, use the git add filename command, and the file is added to the temporary storage area. When you use the git commit-m 'modify remarks command, the file (changes) is written from the staging area to the version library.

answer your question

  1. when you start to modify a file, before executing the git add command (which is still in the workspace ), you can use git checkout-- filename to undo the changes to the file.
  2. once you have used the git add command to add the file to the staging area , you do not want to change the file at this time. You need to use git reset HEAD filename to move the file to the workspace, and then use git checkout-- filenmae in the first step to undo the changes
  3. .

this is not clear in one sentence or two. Give you a link; https://github.com/geeeeeeeee.


checkout does not change the branch (ref)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e46c11-4441c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e46c11-4441c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?