I am using Eclipse for local dev and GitHub as my remote git repo. Eclipse generates several artifacts that I don't want in my remote repo, but I forgot to add those to my .gitignore file. I pushed everything to the remote GitHub repo and realized that the following items were pushed (again, unintentionally):
myapp/
<lots of other stuff>
.classpath --> undesired
.settings --> undesired
.project --> undesired
bin/ --> undesired
So I went back and added the following to my .gitignore:
# Eclipse
.classpath
.project
.settings
bin/
I then committed & pushed. To my surprise, the files are still in my remote repo. I would have expected the following behavior:
I push the .gitignore changes to GitHub
GitHub sees that there are files in its myapp repo that violate the terms of the new .gitignore
GitHub deletes these files/directories from the repo
Now when I go to myapp on GitHub, I don't see them anymore
Is this not the case? What's the fix here?
Git does not parse .gitignore file on each commit on it and, of course, does not apply changes from .gitignore to the whole repository in its commit.
So you need to remove files manually (git rm).
If you need to have this files on your filesystem use git rm --cached
Related
I'm a beginner to using github and I accidentally added this folder to my github but I cannot find a way to remove this please help.
I tried deleting this folder from my main folder and redoing my git pull and push and in the terminal it said that this file as already been removed. But once I pushed my file again the files that needed to be updated were updated but the folder is still on my github repo.
Try:
git rm -r <folder>
git commit -m "remove folder"
git push
The changes will only be saved when you run the commit command
I added a directory with files to the local git repo and did the commit. When it was pushed to github it looked like it was added. When I do a clone from github the directory does not show up. I do not find a .gitignore file. Doing a check-ignore --verbose to one of the files added does not return anything.
For an experiment (with the clone up-to-date) I added a directory "gittest" with a file "hello.txt"; did the commit & push. The push appears to show the addition. A pull in the clone appears to show the addition, but the directory/file does not show. Other than starting a new repo and deleting the old one I am stuck as what to do next.
I have a repository. I pushed files from a folder. Now I don't want to create new Repository. But I want to push files from a new Folder. The folders are almost same. How can I do this with command?
Assuming that you already have the repository created, you can do the following.
cd newfolder
git clone <link-to-clone-from>
Then copy the files to new folder. Check git status -s to see a summary of changed files in new folder after you copy files. Using git diff or beyondcompare can show you the exact changes that you are about to commit next. If everything looks fine, continue with the next steps
git add -a
git commit -m "your commit message"
git push origin master
Assuming you have two folders:
- Old repo folder
- .git
- My old folders
- My old files.
- New repo folder
- My new folders
- My new files.
And you want to replace all stuff in the remote repo from the old repo folder with the new repo folder.
To do that:
First, delete all content except the folder: .git in the Old repo folder.
Then, copy everything except the folder: .git from the New repo folder to the Old repo folder
And run commands in the Old repo folder:
$ git status
To get if everything is fine. Git will detect that you have replaced a lot of files and deleted many of them. Check the output.
$ git add . && git commit -m "Replace with new content"
$ git push
And this will save your changes and send it to remote server.
In Github, i have already a repository, e.g. called "java8"
And under it, i would like to have a sub-folder, e.g. called "01-lambda"
So my folder structure in github should be
java8
01-lambda
02-enums
etc.
Then I want to commit my code to the sub-folder "01-lambda"
How can I do that?
What I tried:
I just created a new folder with a txt file "01-lambda" under the repository "java8", then I tried to commit, but git bash shows they cannot find the sub-file.
I just commit my code directly to repository "java8", but then I need to change path of every files, and add /01-lambda in the path
git init
git add *
git commit -m “my first repo”
git remote add github .git
git remote -v
git push -f github master
I just created a new folder with a txt file "01-lambda" under the repository "java8", then i tried to commit, but git bash shows they cannot find the sub-file.
You need to add before committing, assuming you do have a file inside the new folder (Git would not add just a folder):
git add 01-lambda
git commit -m "add 01-lambda"
I am working on the same project with another person, and we sync our work using Git. Whenever we do a git push / git pull the paths to our external libraries are updated with paths that are valid only for the other person's machine. The paths are defined here:
I have nothing in my .gitignore file. How can I fix this issue?
You have committed some files to your Git repo that are designed to be user-specific, and should not have been committed.
Add a .gitignore file containing at least the following:
.metadata
.classpath
Or better, import one from e.g. gitignore.io.
To remove the files you have already committed to the repo:
git rm --cached -r .metadata
git rm --cached MyProject/.classpath
and commit the changes (including your .gitignore).
The git rm commands will remove the files from the repo, but not from your working directory, so Eclipse can still find them. However, the files will be deleted from the working directory of anyone else who pulls this commit. To work around this, after the other devs have pulled your changes, you can have them do e.g.:
git checkout HEAD^ -- MyProject/.classpath
git checkout HEAD^ -- .metadata
# Unstage the files, if necessary.
git reset HEAD -- MyProject/.classpath
git reset HEAD -- .metadata
After all of this, you should be able to modify those paths per-user, and the changes will not be tracked by Git.
Group the Selenium jars into a User Library that you can reference from the .classpath file, but define differently on each machine. It adds a layer of indirection that you seem to need. http://help.eclipse.org/neon/topic/org.eclipse.jdt.doc.user/reference/preferences/java/buildpath/ref-preferences-user-libraries.htm?cp=1_4_2_0_1_1