How can I reset or revert a file to a specific revision?

前端 未结 30 1947
不思量自难忘°
不思量自难忘° 2020-11-21 11:23

I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous versio

30条回答
  •  日久生厌
    2020-11-21 11:57

    Note, however, that git checkout ./foo and git checkout HEAD ./foo are not exactly the same thing; case in point:

    $ echo A > foo
    $ git add foo
    $ git commit -m 'A' foo
    Created commit a1f085f: A
    1 files changed, 1 insertions(+), 0 deletions(-)
    create mode 100644 foo
    $ echo B >> foo
    $ git add foo
    $ echo C >> foo
    $ cat foo
    A
    B
    C
    $ git checkout ./foo
    $ cat foo
    A
    B
    $ git checkout HEAD ./foo
    $ cat foo
    A
    

    (The second add stages the file in the index, but it does not get committed.)

    Git checkout ./foo means revert path ./foo from the index; adding HEAD instructs Git to revert that path in the index to its HEAD revision before doing so.

提交回复
热议问题