关于git:从存储库中删除本地更改


Remove local changes from repository

所以。烦人的。

为简洁而编辑:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$ git pull origin master
 * branch            master     -> FETCH_HEAD

error: The following untracked working tree files would be overwritten by merge:
    app/models/page.rb
Please move or remove them before you can merge.
Aborting
$ git reset --hard
HEAD is now at d90309f
$ git pull origin master
 * branch            master     -> FETCH_HEAD

error: The following untracked working tree files would be overwritten by merge:
    app/models/page.rb
Please move or remove them before you can merge.
Aborting

$ git rm --cached
usage: git rm [options] [--] <file>...

    -n, --dry-run         dry run
    -q, --quiet           do not list removed files
    --cached              only remove from the index
    -f, --force           override the up-to-date check
    -r                    allow recursive removal
    --ignore-unmatch      exit with a zero status even if nothing matched

$ git pull origin master
From https://github.com/Jinxy5/laughing-octo-lana
 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
    app/models/page.rb
Please move or remove them before you can merge.
Aborting
$ git rm --cached app/models/page.rb
fatal: pathspec 'app/models/page.rb' did not match any files

对类似问题的回答说明git rm --cached可以解决问题,但我做的不对吗?因为它说它不匹配任何文件?可能是因为我运行了Git重置?


这个怎么样:

1
git clean -fd


你一定要看一下我最近写的这篇关于删除本地更改的文章

删除本地Git更改的各种方法

"结论:

很明显我们可以使用

(1)git clean -fgit reset --hard的组合或

(2)江户十一〔2〕。达到预期的效果。

1
git clean -f -d "