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.
Related
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
how to fix the red class to green can be pushed on github, every time I go to github, I don't go to push because it's still red, after editing it's usually green
If files are Red means files are not added to Git.To Add files to git follow below steps
Steps for Add files to git:
Select File which is need to add,next write click on file -> Git->Add
Please refer below screenshot for adding files to git:-
After follow these steps now you can commit and push the files to git.
Steps for Commit files:
Click on VCS->Commit
Refer below screenshot for Commit:-
I hope it works for you
The below file is red because its not added to your git repository.
for adding and committing it to the git repository you must add->commit->push.
There are multiple ways to do so, one way is using the Gui controls available in the android Studio or using the Command line commands.
Below screenshot shows how it is done in android studio.
You can Commit and Push the files whichever you want to be updated in the repository.
Commands to update your new files into repository are :
git stash
git pull
git stash apply
//resolve your conflicts
git add <filename>
git commit -m "<commit message>"
git push
it because you just create a new file and not insert into the commit file, if you binding your git into android studio select VCS -> GIT -> Commit File.
Then on the dialog make sure you have already a checkmark on the file still red, then you can commit the file, after you do that, that will become green when you have changes on your file.
Solved
right clicked the file -> GIT -> Add.
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
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.
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