Git/Android - Cannot commit submodule in assets folder - android

I'm trying to use a submodule in my Android application, and while I was able to add the submodule successful, when trying to commit a change to use the latest version of that submodule, it throws an error.
The submodule is a simple repo that just contains json data that multiple applications are using.
I navigated to the assets directory within my Android app, and added the submodule like normal and gave it an alias "database"
git submodule add https://github.com/.... database
Now, that works but when I updated the submodule, I'm unable to commit the change within my main repo saying "use the the latest version of that submodule"
my_app\src\main\assets\database
"-" Subproject commit 3521bd386c99....
"+" Subproject commit d135dc8cd5b0....
"d135dc8cd5b0...." being the latest version of that submodule.
If I try to commit that change, it'll throw this error.
Could not commit submodules:
my_app/src/main/assets/database
Add them as submodules from Git Shell or remove their .git folders
and add them as a regular directories instead.
But I already added it as a submodule through the Git Shell. Any idea on how to fix this?
Thanks.

You should be able to commit the updated submodule if you commit it all by itself using its directory path:
git commit my_app/src/main/assets/database -m "Updated database submodule"
You should then be able to commit all the other changes you have made to your repository:
git commit -m "Improved flux capacitor code"

Related

how to add a git non-android library project as a sub module, to android project

I am working on project were I have to initialize this repo https://github.com/livekit/protocol as submodule in my android project. How can I achieve this?
First clone the Android project into your local system.
git clone https://github.com/username/repo-name
Then using the git submodule add command, add the URL of the submodule
git submodule add https://github.com/livekit/protocol
Then execute the following commands:
git add .
git commit -m "Commit message"
git push origin master
In the last command replace masterwith the name of branch you are working with.

How can I solve "fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree"?

I have only one commit on master and haven't merged it into the remote. I want to remove my commit, keep my changed files, change my branch, and commit them.
Now I have used git reset --soft HEAD~1, but I am faced with this error:
fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
HEAD~1 is a way to point at "the parent of current commit"
In your situation: the (only) commit on master does not have a parent ...
If your intention is to have this commit on another branch, simply create that other branch:
git checkout -b my/branch
# The above is a shortcut to:
git branch my/branch # Create a new branch `my/branch` on the current commit
git checkout my/branch # Switch to this branch
With one single commit in its history, "removing the commit from master" is the same as "deleting master".
There is no harm in doing it (you can re-create it later): git branch -d master, but you can also live with a local master branch hanging around.
An alternative is to amend the first commit:
# Make your change in the file(s)
git add file_changes
git commit --amend --no-edit
Resource: How can I add a file to the last commit in Git?
If this is from flutter, then the problem is simply from your installation process.
check your .git > refs , if the heads & remote directories are empty, then you simply have incomplete files.
Delete your current flutter folder and download again.
Ensure that 100% of the files are moved/copied during extraction

New commit on Github only few file from all

I have new project in the android-studio. I want to commit the project on the github, I did with VCS - import into version control - share project on github. The problem is, in the repository its only showing the directory like this below:
My repository:
How to fix this?
To update some specific File to the git
1.Launch git bash by right-clicking on the folder on your local system in which you have ".git folder".
2. Run command "git status". --->Command to check if you have modified the required files and saved it
3. Run command git commit -m "<
4.Run command "git push" -- this will commit your changes to the server

Getting "detached HEAD" error despite deleting git submodule

Git seems to be tracking the java folder, but I can't commit changes to the specific file 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.
That folder is not clickable.
Edit: When I do git status in the command line, I get
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.
Edit 3: I tried adding the file itself w/ git add but got an error that the directory is a submodule.
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
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.
To correct this using just the Android Studio interface, try the following:
Make a backup copy of your changed files, just in case this method doesn't merge your changes correctly.
In the version control pane, select the Log tab. It will show you a list of commits.
The top commit should be the newest one. Right click it and select Checkout Revision in the context menu.
If a dialog appears, select Smart Checkout. This will merge your changes with the selected commit.
Your HEAD should now be attached, so you can commit normally now.
When your HEAD is detached, it means you did the commandline equivalent of:
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. I would suggest removing the .git folder inside JustJava/app/src/main/java/com/example/android/justjava.
Using git through terminal, follow these steps:
Backup all the code in a different folder
**Remove 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:
git checkout master
Comparing backed up code with the current code and make the changes you want (if any)
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 and answered in this question.
This works in that it allows the file to be added and committed, but the commit history on this file is lost.

How to push submodule to github using android studio?

I cloned an android project from github. I made changes after cloning and pushed it to the main repository from android studio. Everything worked fine but when I add an external library in my project I can't push it. I think its a sub module. Could anyone tell me how to push external library as a sub module from android studio?
After searching internet I found a simple way to do it. To add a sub-module we need to run this command
git submodule add LIBRARY_URL
and to init the sub module locally
git submodule update --init --recursive
If it is a submodule, you should be able to list the gitlink entry, special mode 160000
$ git ls-tree HEAD mysubmodule
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398 mysubmodule
It should also be recorded in your main repo/.gitmodules file.
In that case, all you need to do is add and commit that entry, and push it.
If it is not, then remove that folder, and add it again as a submodule through command-line (instead of Eclipse/Egit)
git submodule add /url/of/library/repo mysubmodule
git add mysubmodule # no trailing / here)
git commit -m "Add a submodule"
git push toAndroidRemoteRepo

Categories

Resources