Deleting file from Bitbucket causing issue for ignored files - java

I performed number of steps (some mistakes and then correcting them as shown below) and it's now causing issue in Eclipse resulting in not allowing me to switch from master to branch1.
Below is the sequence of steps:
Created master branch and pushed code including .project file by
mistake.
Created branch1 from master and pushed some code there.
Realizing mistake that .project file need not be committed, I switched back to master branch and used
"git rm --cached .project" command to remove that file from repo. Though
on terminal, it showed "rm '.project'", it would still show on bitbucked
repo.
That gave me impression that the file was not removed from repo so I
went to Bitbucket UI and removed that file externally from bitbucket
(.project -> Edit -> Delete).
That deleted my file from repo.
Went back to Eclipse and made a pull request from Eclipse itself. No error was shown.
But now
when I switch to branch1 from master, it's not allowing me to switch
and shows the error:
I put that file in .gitignore file as well (by including /.project) and pushed .gitignore but in vain. It gives me options of "Reset", "Commit" and "Stash" but unfortunately none of them works probably cause git knows this file as "ignored file" / "untracked file". I tried all of them one by one (quite a few times) but this pops up all time.
Any help would be greatly appreciated.

I'm not sure if this is the "ideal" answer but I think, from the command line, you could do a forced checkout of branch1 from master, do a git rm of the .project file and then push the change (the deletion of the .project file) to the remote repo. So it would look something like this:
git checkout -f branch1
git rm .project
git commit -m "Deleting .project dir"
git push origin branch1

Related

Certain Java files in Android Studio not showing up on GitHub Desktop

I have a project in Android Studio, and whatever changes I make in the application in Android Studios usually shows up in GitHub Desktop to push. Below is a screenshot of a history of revisions I've made:
However, at a certain point, I've made java classes in the application that are not being accounted for in GitHub Desktop. The classes that I am unable to push to my repository are highlighted in yellow:
Is there any solution to this?
Follow the commands:
Go to root directory of project and run git status to list uncommitted files.
Run git add . to add all the files to track.
Run git commit -m "your message" to commit files in current track.
Run git pull origin branch_name to get updated data from that branch. (branch_name is your current branch name.)
Run git push origin branch_name to push all committed files.
Now you check status by git status Hope all files will be uploaded.
Have you run git add on the new files? You can't push new files if you don't add them first.
If you are still looking for the answer.
I had the same issue while using Android Studio. In my case .gitignore file at the repo's main directory had a line that pointed to /app folder of my project. I just removed it and problem solved.
In general, you can have multiple .gitignore files so follow the below steps to fix this type of issue:
Go to your root directory of the git repo.
Search for all .gitignore files (In my case I found 3 files. )
See which of the files is causing the issue by simply commenting all the lines of a file.
Once you have the identified the file, now search for the line that is pointing to the files that you are interested and remove it.

Push the gitignore file alone at the begin

We are five students in a team and we must work in the same project using git.
What i did is:
create an empty project
add gitignore file
The gitignore file
contains:
*.class
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
git init
git add .
git commit -m "Initial commit"
set up the remote and push
But we have a conflict in nbproject/private/private.properties file.
This file contains:
user.properties.file=C:\\Users\\Houssem\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
user.properties.file=C:\\Users\\ASUS\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
One of us he had cloned the repository and he can't add any java class in his local project.
You have confirmed in a comment that the output of git ls-files | grep nbproject/private/ contains line.nbproject/private/private.properties.
That means the file line.nbproject/private/private.properties is part of the repository.
You need to remove the file with git rm line.nbproject/private/private.properties,
and then commit the changes.
After that none of your collaborators should get any conflicts on this file.
Having nbproject/private/ in the .gitignore file should normally prevent line.nbproject/private/private.properties from getting added to the repository.
But it's possible that the file was added to the repository before .gitignore was created,
or that one of the collaborators force-added it (git add -f ...).
If possible, you might want to set up NetBeans to keep the project workspace (I believe this is called "Project" in NetBeans) outside of the actual repository and code, since this contains absolute references and (I'm assuming here) personal preferences.
I have no experience with NetBeans, but in Eclipse this works just fine.
Keeping the workspace files separate should also allow each developer to use an editor of his or her choice instead of being locked to one.

Processing Jars in Eclipse

I have recently started working with a friend on eclipse, using Processing.
All the commits are fine and we can Push and Pull them correctly, but there is one problem:
We import an external jar from proccessing ("Core.jar") which is saved on each one of ours computers.
Every time that we Pull a new commit, ("Core.jar") directory changes and we have to remove the jar and reload it so we can Run the code.
Ive searched about gitIgnore but I do the ("Reset Option" and the "Ignore option") but it doesn't seem to work since the Jars problem is again.
I use Github Desktop.
As commented, if that jar is versioned instead of being generated or loaded, you should remove it from the repo first:
You can open a command-line from GitHub Desktop, and type:
git rm --cached -- Core.jar
git add .
git commit -m "record Core.jar deletion"
git push
Then your .gitignore rule should be immediately effective.
Said .gitignore should include "*.jar", or at least "Core.jar" (without the double-quotes)

Git ignore not excluding my .project file

I am using git for the first time and I am trying to make a commit. I want to ignore all .project and .settings files so I went to my .gitignore file and added .project, .settings and saved. When I did that the .settings file doesn't appear anymore, however, I still see my .project file when I do git -status. Also, why is the .xml and java file in a different section that the .jar files:
Your git status output is showing you two types of files:
Changes not staged for commit
These are files which Git is tracking, and these files have been modified since the previous commit. But, the changes have not yet been staged. Unless you stage the changes using git add, they will not be committed. Here is how you would stage the change to the web.xml file:
git add path/to/web.xml
Assuming you really just started working, then the most likely explanation for why the .project is showing up as being tracked by Git is that you somehow added it. To fix this, you can try using:
git rm --cached .project
This removes the .project file from being tracked by Git. It would also remove it from the remote repository, but since you just started working and haven't pushed yet, this is a moot point.
Untracked files
These are files which Git is completely ignoring. From Git's point of view, these files are not there. I can see that you have a number of JAR files listed as untracked, which is probably a good thing, since in general it is a bad idea to add binary files, especially dependencies, to your Git repository. Should you see a source file listed as untracked, you could also run git add to add that file to Git.
The reason it is generally considered bad practice to add binaries to a Git repository is that Git doesn't handle diffs of binaries very well. Suppose you add a 1MB JAR file. Each time it changes, which could be fairly often if you are doing some open source stuff, a diff has to be stored for that binary. But, Git often will interpret the diff as being deleting the old file and replacing it with the entire contents of the new file. In other words, Git basically versions the entire binary for each change. Over time, this can cause your repository to become large and bloated, and it can be difficult to get rid of those binaries from your history. So, unless absolutely necessary, avoid storing binaries in your Git repository.

BitBucket repo has file which is not in my src folder

I used to have a java package called "Utils" and I renamed it to "utils" (uncapitalized) but it's still in the BitBucket repo. I tried to remove it using git by executing this command: "git rm src/me/lordal/gom/dtv/Utils/" but it says "fatal: pathspec 'src/me/lordal/gom/dtv/Utils/' did not match any files". So it's not in my src folder but it's still online on BitBucket.
As you can see here it has the "Utils", "Listeners" and the "Game" package two times but on the one capitalized.
Git does not do well with differences in capitalization of file names. You will need to specifically inform git that you changed the file name.
Two solutions to this problem can be found here
The first is to rename the file to some completely different name Ut-ils for example (using git mv) then change it to utils.
The second is to use git mv -f Utils utils
To fix the problem, changing the name of utils to an intermediate name then running git rm Utils (you may need to specify -r due to recursion. (The name change is necessary to make sure that git does not try to remove the proper file.)
It may be worth doing this on a fresh clone of the repo.
Try this then do the steps below.
git -rm -r Utils/
on your local repo
git add -m // adds all the stuff you want to commit
git commit -m "updated util name"
git push origin master (or whatever your branch name)
This will update the bitbucket.

Categories

Resources