Selectively revert or checkout changes to a file in Git?

后端 未结 4 1215
情歌与酒
情歌与酒 2021-01-30 06:09

Is there a command that allows you to partially undo the changes to a file (or files) in the working directory?

Suppose you have edited a file a lot but you realize that

4条回答
  •  無奈伤痛
    2021-01-30 06:35

    git checkout $file reverts the state of the file $file to the last committed state. I think you can use git checkout SHA-1 -- $file to revert the file to the commit identified by SHA-1.

提交回复
热议问题