Discuss / Git / 为什么老师的提交的提示都是git commit --<file>,而我是git restore <file>

为什么老师的提交的提示都是git commit --<file>,而我是git restore <file>

Topic source

烁靥619

#1 Created at ... [Delete] [Delete and Lock User]

Administrator@LW-20200507VEDB MINGW64 /g/hdl (master)

$ git status

On branch master

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git restore <file>..." to discard changes in working directory)

        modified:   world.txt

no changes added to commit (use "git add" and/or "git commit -a")

云翼之影

#2 Created at ... [Delete] [Delete and Lock User]

我的也是,然后我特地测试了一下

git restore <file>

git checkout -- <file>

这两个命令起到的效果都一样的,没提交时,将文件修改撤销

其他的还不知道,等弄明白再处理

云翼之影

#3 Created at ... [Delete] [Delete and Lock User]

文章看完了,然后在回退未add到暂存区的文件时直接用

git restore <file>

git checkout --<file>

效果一样

当回退暂存区时(此时文件已经add到暂存区,还未进行commit),使用

git restore --staged <file>

git reset HEAD <file>

效果一样

git restore 是git 2.23版本新增的命令,用来代替身兼数职的git checkout。功能是一样的。


  • 1

Reply