git 为什么添加新目录后“没有任何提交”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5931505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is there "nothing to commit" after I added my new directory?
提问by Snowman
Ok this is really frustrating me. I'm used to working with SVN, and am new to git. I had a folder called X in git already. A collobarator made changes to X and commited it, and I updated it. I made changes to it, and now I want to save it as X2 as a new folder. So I duplicated the X folder locally, and now I want to add this to github. So I did
好吧,这真的让我很沮丧。我习惯使用 SVN,并且是 git 新手。我已经在 git 中有一个名为 X 的文件夹。一个合作者对 X 进行了更改并提交了它,然后我更新了它。我对其进行了更改,现在我想将其另存为 X2 作为新文件夹。所以我在本地复制了X文件夹,现在我想把这个添加到github。所以我做了
cd X2
git init
git add X2
git commit -m "changes"
git push origin master
I also tried being in the parent directory where both X and X2 are located, then git add X2 and commit and push, but I keep getting "nothing to commit".
我也尝试在 X 和 X2 所在的父目录中,然后 git add X2 并提交和推送,但我一直得到“没有提交”。
What am I doing wrong?
我究竟做错了什么?
回答by manojlds
Why are you doing a git init
before adding X2
. Git init is done only when creating a repo. Also note that git add
only adds files, not directories.
为什么要git init
在添加X2
. Git init 仅在创建 repo 时完成。另请注意,git add
仅添加文件,而不添加目录。
Apart from that git add X2
should work perfectly fine, when you are in root / parent. From within the folder itself do git add .
除此之外git add X2
,当您处于 root / parent 时,应该可以正常工作。从文件夹本身做git add .
回答by Adam Dymitruk
Commit a proper .gitignore file first. Then you can do a 'git add -A'. All the files you don't want will be skipped.
首先提交一个正确的 .gitignore 文件。然后你可以做一个'git add -A'。您不需要的所有文件都将被跳过。
回答by Kev
Try using "git add ." this will add all the files in the current working directory to the stage (aka ready to be committed). Hope this works!
尝试使用“git add”。这会将当前工作目录中的所有文件添加到阶段(也就是准备提交)。希望这有效!