【问题标题】:How can I undo adding a new file to git? [duplicate]如何撤消向 git 添加新文件? [复制]
【发布时间】:2016-07-22 06:14:55
【问题描述】:

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

要提交的更改: (使用“git reset HEAD ...”取消暂存)

    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 中,现在我看到了:

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

然后我意识到我不想 push 到 repo 这个文件:

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

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

【问题讨论】:

    标签: git


    【解决方案1】:

    你的问题有答案:

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

    要取消暂存文件,请键入:

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

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

    【讨论】:

    • 谢谢,几分钟后我会尽快接受这个答案;)
    猜你喜欢
    • 2017-03-02
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 2015-08-05
    相关资源
    最近更新 更多