[英]AndroidStudio is not committing MainActivity.java to Github
Git seems to be tracking the java folder, but I can't commit changes to the specific file MainActivity.java
. Git似乎跟踪java文件夹,但我不能提交对特定文件
MainActivity.java
更改。 I get a "Changes not staged for commit" The diff shows the changes, but I can't commit it. 我得到一个“未提交更改的更改”差异显示更改,但我无法提交。
Also, I can't go down into the folder in Github. 另外,我不能进入Github的文件夹。
That folder is not clickable.
该文件夹无法点击。
Edit: When I do git status
in the command line, I get 编辑:当我在命令行中执行
git status
时,我得到了
user:JustJava juil$ git status
HEAD detached at 93ea9a1
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)
(commit or discard the untracked or modified content in submodules)
modified: app/src/main/java/com/example/android/justjava (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
Edit 2: I have checked out the latest commit as some have suggested but still get the detached head error. 编辑2:我已经检查了一些有人提出的最新提交,但仍然得到了分离头错误。
Edit 3: I tried adding the file itself w/ git add
but got an error that the directory is a submodule. 编辑3:我尝试添加文件本身w /
git add
但得到一个错误,该目录是一个子模块。
JustJava juil$ git add app/src/main/java/com/example/android/justjava/MainActivity.java
fatal: Pathspec 'app/src/main/java/com/example/android/justjava/MainActivity.java' is in submodule 'app/src/main/java/com/example/android/justjava'
I tried running git submodule status
and got the error 我尝试运行
git submodule status
并得到错误
fatal: no submodule mapping found in .gitmodules for path 'app/src/main/java/com/example/android/justjava'
I tried deleting .git
in the submodule, but the same error keeps popping up. 我尝试在子模块中删除
.git
,但同样的错误不断弹出。
To correct this using just the Android Studio interface, try the following: 要使用Android Studio界面更正此问题,请尝试以下操作:
Log
tab. Log
选项卡。 It will show you a list of commits. Checkout Revision
in the context menu. Checkout Revision
。 Smart Checkout
. Smart Checkout
。 This will merge your changes with the selected commit. When your HEAD is detached, it means you did the commandline equivalent of: 当您的HEAD分离时,这意味着您执行的命令行相当于:
git checkout <UUID of previous commit>
The grey folder that was created is called a submodule, it happens when you initialize a git repository inside another git repository. 创建的灰色文件夹称为子模块,当您在另一个git存储库中初始化git存储库时会发生这种情况。 I would suggest removing the .git folder inside
JustJava/app/src/main/java/com/example/android/justjava
. 我建议删除
JustJava/app/src/main/java/com/example/android/justjava
的.git文件夹。
Using git through terminal, follow these steps: 使用git through terminal,请按照下列步骤操作:
Backup all the code in a different folder 备份不同文件夹中的所有代码
**Remove JustJava/app/src/main/java/com/example/android/justjava/.git" **删除JustJava / app / src / main / java / com / example / android / justjava / .git“
Checkout out master or the current branch you're on (default: master) 签出主人或您当前的分支(默认:主)
In order to checkout master, go to the folder where you git project is through the terminal (linux or mac) or git bash (if you're on windows), then do: 为了结帐主人,通过终端(linux或mac)或git bash (如果你在Windows上)转到git项目所在的文件夹,然后执行:
git checkout master
Since justjava
folder turned out to be a submodule, in the super directory, I called git rm -rf --cached justjava
as suggested by @fusiongate 由于
justjava
文件夹原来是一个子模块,在超级目录中,我git rm -rf --cached justjava
的建议调用了git rm -rf --cached justjava
justjava
This works in that it allows the file to be added and committed, but the commit history on this file is lost. 这有效,因为它允许添加和提交文件,但此文件的提交历史记录将丢失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.