简体   繁体   English

AndroidStudio没有将MainActivity.java提交给Github

[英]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的文件夹。

项目结构 提交错误

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:我已经检查了一些有人提出的最新提交,但仍然得到了分离头错误。

当前的git日志

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界面更正此问题,请尝试以下操作:

  1. Make a backup copy of your changed files, just in case this method doesn't merge your changes correctly. 制作已更改文件的备份副本,以防此方法未正确合并您的更改。
  2. In the version control pane, select the Log tab. 在版本控制窗格中,选择“ Log选项卡。 It will show you a list of commits. 它会显示一个提交列表。
  3. The top commit should be the newest one. 最高提交应该是最新的提交。 Right click it and select Checkout Revision in the context menu. 右键单击它并在上下文菜单中选择Checkout Revision
  4. If a dialog appears, select Smart Checkout . 如果出现对话框,请选择Smart Checkout This will merge your changes with the selected commit. 这会将您的更改与所选提交合并。
  5. Your HEAD should now be attached, so you can commit normally now. 你的HEAD现在应该被附加,所以你现在可以正常提交。

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,请按照下列步骤操作:

  1. Backup all the code in a different folder 备份不同文件夹中的所有代码

  2. **Remove JustJava/app/src/main/java/com/example/android/justjava/.git" **删除JustJava / app / src / main / java / com / example / android / justjava / .git“

  3. 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 
  4. Comparing backed up code with the current code and make the changes you want (if any) 将备份代码与当前代码进行比较并进行所需的更改(如果有)
  5. Commit new code 提交新代码

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM