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
Related
I've been running Android Studio on Windows, with git doing the versioning, and git pushing using git bash for Windows. I've been doing the same thing for all that time, without issue.
Then today, in the event log in Android Studio after opening I see:
17:29 VcsException
error: Could not read 5188c7b8677be145b04f079e6f9cab08e5c19240
fatal: Failed to traverse parents of commit 50da9e67a67598125b860984db9e493bd5d1f2ee
during executing git -c core.quotepath=false log HEAD --branches --remotes --max-count=2000 --pretty=format:%x01%H%x02%ct%x02%an%x02%at%x02%ae%x02%cn%x02%ce%x02%P%x02%s%x02%b%x02%B%x02%d%x03 --encoding=UTF-8 --decorate=full --
And when I try a git operation in the git bash console (Windows) I get:
$ git commit -m 'new stuff'
fatal: unable to read tree 4dfc5598677be145b04f079e6f9cab0833555566
The following is an extract from running git fsck... there is a long list which annoyingly in git bash is not scrollable or selectable:
$ git fsck
dangling blob 7be145b04f079e6f9cab0835664dfc5598673555
missing blob e6f9cab0835664dfc559e145b04f07986735557b
missing tree b04f07986735557be6f9cab0835664dfc559e145
... (lots of dangling blob, a few missing blob, one missing tree) ...
What can I do to fix this?
So, since I've been pushing regularly to the remote repo so I know that is pretty up to date, I followed the low-tech suggestion set out here, combined with the first comment to that suggestion.
So:
create a temporary folder in whatever location you want
clone the repo into that folder with git clone
git#bitbucket.org:myaccount/myproject.git
move the .git folder in the existing project folder out into another temporary folder somewhere
move the .git folder from the repo cloned in step 2 into the project folder, to replace the old one moved out in step 3
and that was it... a git add / commit / push we seem to be
back on track
The problem is when i want pull from git , i need to commit first. I just commit few file that i made change but still can't pull because it detect this generated build file is changed so i commit all file then when i pull then it will be a conflict. Need to rebuild but sometimes it take long time, sometimes need to invalidate and restart. But sometimes the project can't run again.. How can i prevent this problem ?
You need to read about how to use Git Ignore files - things listed in gitignore are not synced.
Intermediates and any other files in the build directory should not be added to version control.
This is a great starting point for what contents should be in your gitignore file:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
I stole it vertabim from this answer, so you can find additional information there
Try to use git stash command before git pull. That command will save your local changes and clean working directory. You could always bring back saved changes (e.g., after git pull is finished) using git stash pop command. See git help stash for details
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.
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.
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.