I am doing git pull, It says
error: Your local changes to the following files would be overwritten by merge:
Gemfile
Please, commit your changes or stash them before you can merge.
Aborting
I don't remember doing any changes to gemfile.
On git status nothing is shown apart from all the files that I have removed.
How can I fix it. And How can I remove all the deleted files being shown while I do git status.
Please help.
For this scenario you have to use git stash refer this link (https://git-scm.com/book/no-nb/v1/Git-Tools-Stashing)
Removal of files is also a change from the previous commit, so commit your changes by using first git add(the files you have edited, not sure about removed) then then git commit. After that, take merge, or,
You can also write git checkout gemfile before taking merge, if you are sure that you haven't made any changes to it. This will restore gemfile to previous commit. Then take the merge.
Related
I know git stash, but somehow either I am doing something wrong or my problem is not as common as I think.
Scenario: I am coding, committed and pushed a version, doing further code, then to make a decision I would like to test something. For that, I'd love to save the current local files away and return to that state later on to try another solution. Note: in an intermediate un-committed state. Something one would do normally by zipping the project folder and restoring it later.
git stash for me has the crux, that I cannot tell it to simply re-apply the stashed content, ignore anything else, simply recover what was stashed. With git stash apply --force I get (of course) warnings that files are not committed.
Any help?
Use git checkout instead of git stash apply:
$ git checkout stash -- .
This will restore all the files in the current directory to their stashed version.
If I understand the question correctly you can store all untracked files with git stash --include-untracked (or git stash -u for shorten).
After you finish with the tests just revert the stash with git stash pop.
I am working on a Rails project!
Excuse for not adding .gitignore
I have accidentally committed and pushed 'database.yml' in to my feature branch. A pull request was created from the feature branch to master branch a few days ago and is not yet merged. There are multiple commits done as part of this pull request and the commit containing 'database.yml' is the fourth last commit.
Others are also working as part of this project and they are merging the changes to master and we are pulling those changes in to our feature branch in-between. Thus, in our feature branch, we have got commits from others which are done after the faulty commit.
so I wish to do a 'git rm' and 'git push' the same file again to resolve this issue (as the PR is not yet merged). Will that create problem?
If you remove the database.yml that will be another commit on top, and nobody will be affected.
Notice, however, that the database.yml will still be part of the history and can be accessed via git log. If that file contains sensitive information, it will be findable by others.
Delete the file from your local system then add the changes to a commit using
git add <FILE_PATH> command and then commit and push the changes and it should be fine.
The right way to remove it properly is to reverse the changes you made to the file and commit it.
Another, dirtier way, is to open the commit and remove the changes and force push it to the repo. But you need the proper rights for this. Others will also have problems if they try to pull changes then.
I've made a stupid error which has messed up my database on a Rails App I'm working on. Luckily I'm on a branch and haven't committed any changes so the version on Git is in working order.
How do I now pull through the Git version and update to Sublime so I can carry on working as if nothing happened?
I've just done git pull origin master but it says up to date so I've obviously done something wrong.
I'm not keen on a db:drop so I'd rather do it this way if possible.
You can't pull again, because you already pulled every commit from your remote.
Add changes, stash them, remove the stash:
git add --all && git stash && git stash drop
This will remove every uncommited change and bring you back to the latest commit on the current branch.
git checkout 01h5y77d (find this in git, a version of the app which works)
This would print "HEAD is now at 01h5y77d..."
You don't have to commit because you did not commit the mistakes yet :)
I'm trying to push my Rails project to Heroku, but Git isn't allowing me to do anything at the moment. Here's what I've done so far:
git push heroku failed because the heroku branch was "ahead" of my local branch, which should not have been possible.
I pulled and there was a conflict with .idea/workspace.xml. I wasn't able to find out what that file is, but it's huge and Git wrote all kinds of garble to it. Too much to manually "resolve" conflicts.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
I ran git add -A (also tried git add . and git add)
git commit --amend fails because "You are in the middle of a merge"
git merge --abort fails because "Untracked working tree file '.idea/workspace.xml' would be overwritten by merge (despite the fact that the file has been moved)
git reset --merge fails for the same reason.
How can I make Git work again?
.idea/workspace.xml
This file is your idea workspace files. They are generated by IntelliJ tools.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
Simply add the folder to your .gitignore but since its already committed you will have to remove it from the repository:
# Quit the merge
git merge --abort
# remove the whole folder from the repo
git rm -rf --cached .idea/
# add it to the .gitignore: idea/
# add and commit your changes
git add .- A
git commit -m " Removed idea folder"
git push origin <branch>
If you still unable to do it?
First reset the code to the previous state and then do the above code again.
The reset will take you to your last commit before the pull
git commit -am "message" worked (as opposed to amending a commit)
I have resolved a similar problem by simply deleting the workspace.xml file. By building and running the program again idea will autogenerate a compatible file.
Doing a pull from master into my local branch on a shared ROR project. Git says:
branch master -> FETCH_HEAD error: Your local changes
to the following files would be overwritten by merge:
config/environments/development.rb Please, commit your changes or
stash them before you can merge. Aborting
development.rb is not showing up as having been modified, and, in fact, when I actually do modify it, it still doesn't show as having been modified. This is happening on all branches, effectively preventing me from merging in master.
I should say here that I am a designer on this project and my ROR and Git skills are not huge (I have mostly been using the Tower GUI for managing branches). However, I've been successfully contributing to the project for over a year and never came across this issue before.
If you type 'git status' do you see development.rb in the list of untracked files? If so you need to 'git add' it and commit.
Alternately, in the root of your project look at .gitignore and see if it's listed in there for some weird reason. It shouldn't be, but it's worth looking.
My gut feeling that you are using git update-index --assume-unchanged development.rb, but don't remember it. If it is the case, use --no-assume-unchanged then.
It is hard to say without looking at your .gitignore but you could have config/environments/development.rb in that file, in which case you wouldn't see changes.
But that isn't the real issue, it sounds like you just need to commit then pull. This is what I would do.
Add config/environments/development.rb to your commit, commit changes then pull. If that doesn't work, I would just delete your local copy and clone a new one.
I hope that helps.