How to clear $HOME/.gradle/caches/ whenever I commit in git? - android

How to clear $HOME/.gradle/caches/ whenever I commit in git?
Is it possible for android studio to detect whenever something changes like git commit and would trigger clear gradle cache?
My main problem is that I have a script in build.gradle:
def gitCommitCount = "git rev-list HEAD --count".execute().text.trim()
These script will be used in naming my apk.
But the problem is , it wont update whenever I commit and the apk will install incorrectly using the previous apk version name. like myapp-130.apk and the new one is myapp-131.apk but the myapp-130.apk will be used instead.

It seems your script is run after git commit is done. Is it possible to clear the cache in your script? If not, it could be done in a post-commit hook.
Touch a file named post-commit in .git/hooks/ and make it executable. It could be implemented like this in bash
#!/bin/bash
rm -rf $HOME/.gradle/cache/
By default, whenever a commit is made in the current repository, the hook is triggered.

Related

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

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.

Removing build folder from git

I have pushed a build folder to my remote repo; but the .gitignore file clearly has this line (/payu_ui/build); But i found out since the build files were already tracked once and now that i wrote a line in .gitignore will not really ignore the build folder. So i want to remove it from git from being tracked (the complete build folder) so i used this command
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch payu_ui/build/' --prune-empty --tag-name-filter cat -- --all
But every time i run this command it gives an err saying
fatal: bad revision 'rm'
So what is going wrong; every time i click the commit option from IDE it shows that 1300 files needs to be committed (its annoying me)
Any help will be appreciated;
1. I dont want to track these build files(from payu_ui lib)
2. I dont want to push them to remote repo (but its already thr and beleive once i track from local and push them it gets deleted in remote repo; if it doesn't i'll manually delete in remote repo)
Well you may just do the following,
Remove the line from gitignore for now.
Locally delete the folder.
Push out the change so the folder gets deleted from remote as well.
Now add the line to gitignore.
I recently faced the problem and that is what i did.
remove those build files (or whole folder) from your computer
rm -r [direction to files]
then add, commit and push all your changes (actually the change will be removing those files from repository), if you have set .gitignore
file properly, git will stop tracking those files

Android Studio .iml git issue

When I try to make a "git pull" I get the following message :
error: The following untracked working tree files would be overwritten by merge:
blablabla.iml
Please move or remove them before you can merge.
Aborting
I try to checkout the .iml and add it to my gitignore but I keep receiving this message. Does someone know how to fix it?
Regards
Jose
Git will not allow you to execute a pull that would cause you to lose changes in your working directory (this is good for obvious reasons).
Adding the file to your .gitignore will tell git not to push your changes to that file to other repositories, but it does not prevent you from pulling other repositories changes of those files. So this actually has no effect on the operation you are trying to do. As a side note, it is not recommended to put iml files in a .gitignore: What should be in my .gitignore for an Android Studio project?.
Here's what I would do:
Stash your local changes: git stash save "My iml changes"
Then checkout the code: git pull
Optionally, get your local changes out of the stash: git stash pop. Or, if you prefer, git stash drop stash#{0} (As pointed out by #LoyalRayne, you might not need these changes). See the differences with git stash show stash#{0}.
If you want the contents that are currently in the repo, you can revert your local changes first with git checkout blablabla.iml, then pull. Or, if you want to keep your local changes, do git stash, then git pull, then git apply.
After doing the above steps, you may add the file to .gitignore. Make sure to remove it from source control as well with git rm --cached blablabla.iml. Note that when it is remove from source control, it will get deleted on other people's machines when they do their next git pull, so they will want to create a backup.

git push after multiple add and remove

A few days ago I create a repository with an android project that I have been working on. Since then I have deleted a number of files and have added a number of others. Now I want to push my new changes to github. How do I do that? What are the commands to issue? I know I have o commit and then push to master. But how do I tell git that I have added and deleted a number of files? Normally I just do git add . since normally I am adding stuff. But this time I have x new files and y deleted files.
You can use git add --all . to record all changes, including deletions. From the man page:
-A
--all
Like -u, but match against files in the working tree in addition to the index. That means that it will find new files as well as staging modified content and removing files that are no longer in the working tree.
If you want more granular control, use git rm <filespec> to remove files from the index.
After that, commit and push as usual.
To push my changes I do:
1. git add .
2. git commit -m "write my comments for change"
3. git push origin<< provide my credentials

Categories

Resources