我见过其他问题。他们说如果想要在git中重命名文件,只需使用git mv
。
但我只是使用Mac GUI重命名了一个文件(选择文件,输入按钮,重命名)。我将文件夹Samples/OculusWorldDemo/Bin/Mac/Release/data/
更改为Samples/OculusWorldDemo/Bin/Mac/Release/dataInUse/
并进行了其他一些更改。但我无法将新文件夹dataInUse添加到git。
这是我的命令和git响应:
ken@rescomp-14-293006:~/Dropbox/aaRA/杂七杂八相关/OculusSDK$ git status
On branch changeByIterNum
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: LibOVR/Lib/Mac/Release/LibOVR.build/build-state.dat
deleted: Samples/CommonSrc/data/iris.data3D
modified: Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
modified: Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
modified: Samples/OculusWorldDemo/Bin/Mac/Release/.DS_Store
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.app.dSYM/Contents/Resources/DWARF/OculusWorldDemo
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.app/Contents/MacOS/OculusWorldDemo
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo.dia
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo_Scene.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/ReadDataRunML.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/OculusWorldDemo.dep
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/build-state.dat
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/.DS_Store
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.001 500000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.01 10000000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.01 2000000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.05 500000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/displayDataFirst2D.py
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/displayDataFirst3D.py
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data1
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data2D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data3D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.datatest
modified: Samples/OculusWorldDemo/OculusWorldDemo.cpp
modified: Samples/OculusWorldDemo/OculusWorldDemo.h
modified: Samples/OculusWorldDemo/ReadDataRunML.cpp
modified: Samples/OculusWorldDemo/ReadDataRunML.h
deleted: Samples/OculusWorldDemo/data/iris.data3D
deleted: Samples/data/iris.data3D
deleted: data/iris.data3D
Untracked files:
(use "git add <file>..." to include in what will be committed)
Samples/LibOVR_With_Samples.xcworkspace/xcshareddata/LibOVR_With_Samples.xccheckout
no changes added to commit (use "git add" and/or "git commit -a")
ken@rescomp-14-293006:~/Dropbox/aaRA/杂七杂八相关/OculusSDK$ git add .
ken@rescomp-14-293006:~/Dropbox/aaRA/杂七杂八相关/OculusSDK$ git status
On branch changeByIterNum
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .DS_Store
modified: LibOVR/Lib/Mac/Release/LibOVR.build/build-state.dat
new file: Samples/LibOVR_With_Samples.xcworkspace/xcshareddata/LibOVR_With_Samples.xccheckout
modified: Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
modified: Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
modified: Samples/OculusWorldDemo/Bin/Mac/Release/.DS_Store
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.app.dSYM/Contents/Resources/DWARF/OculusWorldDemo
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.app/Contents/MacOS/OculusWorldDemo
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo.dia
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo_Scene.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/ReadDataRunML.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/OculusWorldDemo.dep
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/build-state.dat
modified: Samples/OculusWorldDemo/OculusWorldDemo.cpp
modified: Samples/OculusWorldDemo/OculusWorldDemo.h
modified: Samples/OculusWorldDemo/ReadDataRunML.cpp
modified: Samples/OculusWorldDemo/ReadDataRunML.h
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: Samples/CommonSrc/data/iris.data3D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/.DS_Store
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.001 500000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.01 10000000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.01 2000000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.05 500000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/displayDataFirst2D.py
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/displayDataFirst3D.py
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data1
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data2D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data3D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.datatest
deleted: Samples/OculusWorldDemo/data/iris.data3D
deleted: Samples/data/iris.data3D
deleted: data/iris.data3D
ken@rescomp-14-293006:~/Dropbox/aaRA/杂七杂八相关/OculusSDK$ git add --all .
ken@rescomp-14-293006:~/Dropbox/aaRA/杂七杂八相关/OculusSDK$ git status
On branch changeByIterNum
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .DS_Store
modified: LibOVR/Lib/Mac/Release/LibOVR.build/build-state.dat
deleted: Samples/CommonSrc/data/iris.data3D
new file: Samples/LibOVR_With_Samples.xcworkspace/xcshareddata/LibOVR_With_Samples.xccheckout
modified: Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/UserInterfaceState.xcuserstate
modified: Samples/LibOVR_With_Samples.xcworkspace/xcuserdata/ken.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
modified: Samples/OculusWorldDemo/Bin/Mac/Release/.DS_Store
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.app.dSYM/Contents/Resources/DWARF/OculusWorldDemo
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.app/Contents/MacOS/OculusWorldDemo
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo.dia
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/OculusWorldDemo_Scene.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/Objects-normal/x86_64/ReadDataRunML.o
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/OculusWorldDemo.dep
modified: Samples/OculusWorldDemo/Bin/Mac/Release/OculusWorldDemo.build/build-state.dat
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/.DS_Store
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.001 500000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.01 10000000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.01 2000000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/2D display/0.05 500000.png
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/displayDataFirst2D.py
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/displayDataFirst3D.py
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data1
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data2D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.data3D
deleted: Samples/OculusWorldDemo/Bin/Mac/Release/data/iris.datatest
modified: Samples/OculusWorldDemo/OculusWorldDemo.cpp
modified: Samples/OculusWorldDemo/OculusWorldDemo.h
modified: Samples/OculusWorldDemo/ReadDataRunML.cpp
modified: Samples/OculusWorldDemo/ReadDataRunML.h
deleted: Samples/OculusWorldDemo/data/iris.data3D
deleted: Samples/data/iris.data3D
deleted: data/iris.data3D
答案 0 :(得分:1)
添加新名称并删除旧名称:
git rm --cached old_name
git add new_name
鉴于您已使用与以下内容相同的文件管理器重命名了文件:
git mv old_name new_name
您可以使用一些草率的shell脚本自动为所有文件创建它(仅在Linux上测试):
git status | grep -A1024 -E '^Changes not staged' | grep 'deleted:' | cut -d: -f2 | xargs git rm --cached
git status | grep -A1024 -E '^Untracked' | grep -E '^\s+\w' | xargs git add
之后(足够有趣)git status
将打印您重命名的文件。
注意:带有空格的名字可能对那些oneliners来说是个问题......