如何撤消向git添加新文件?


How can I undo adding a new file to git?

本问题已经有最佳答案,请猛点这里访问。

我做了git status,看到了一堆新文件,例如:

要提交的更改:(使用"git reset head…"来解除锁定)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    new file:   project/swiftFile1.swift
    new file:   projec/swiftFile2.swift

Changes not staged for commit:
  (use"git add <file>..." to update what will be committed)
  (use"git checkout -- <file>..." to discard changes in working directory)

    modified:   project.xcodeproj/project.pbxproj
    modified:   project.xcworkspace/xcuserdata/M.xcuserdatad/UserInterfaceState.xcuserstate

    Untracked files:
  (use"git add <file>..." to include in what will be committed)

    project.xcworkspace/xcuserdata/M.xcuserdatad/WorkspaceSettings.xcsettings

我做了git add -A,它把上面所有的文件都添加到了git中,现在我看到了:

1
2
3
4
5
6
7
8
9
Changes to be committed:
  (use"git reset HEAD <file>..." to unstage)

    modified:   project.xcodeproj/project.pbxproj
    modified:   project.xcworkspace/xcuserdata/M.xcuserdatad/UserInterfaceState.xcuserstate
    new file:   project.xcworkspace/xcuserdata/M.xcuserdatad/WorkspaceSettings.xcsettings
    modified:   project/Base.lproj/Main.storyboard
    modified:   project/swiftFile1.swift
    modified:   project/swiftFile2.swift

然后我意识到我不想让ecx1〔2〕去回购这个文件:

1
project.xcworkspace/xcuserdata/M.xcuserdatad/WorkspaceSettings.xcsettings

所以在我执行git push之前,我可以做些什么来停止提交这个特定的文件(但不能从硬盘中删除它)?


你的问题有答案:

1
Changes to be committed: (use"git reset HEAD ..." to unstage)

要取消文件的存储,请键入:

1
git reset HEAD project.xcworkspace/xcuserdata/M.xcuserdatad/WorkspaceSettings.xcsettings

我可以补充一点,这不会撤消您对文件所做的更改。