Accidentally committed and pushed 'database.yml' to Rails Git Repo - ruby-on-rails

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.

Related

how to delete duplicate local branch in git which does not exist

I searched for similar questions posted here and on the web, but none of them refer to my case.
In some way, I accidentally created a duplicate local branch as you can see in the attached screenshot. My guess is that I created it somehow when I was working with git stash with multiple stashes.
This duplicate branch appears only locally. And moreover, the command git branch in this repo returns only the master branch.
How can I fix this and remove the duplicate local branch? I do want to keep the tags in their place (and I do see them in GitHub so they indeed exist in origin/master branch although they do not appear here in origin/master). Thank you for your help
Editing due to comments:
Before all that mess I accidentally caused, I only saw a single line in the git graph (the blue one) and the tags appeared on it. there was no parallel line next to it showing the same commits. BTW, I cloned the repo to a new location and there I see what I expect - a single line with the tags appear on it. Moreover, I can't push to git from VSCode, but I do succeed in pushing from gitbash, this makes me wonder whether this is some bug in VSCode.
git log --all --graph --format=oneline --decorate prints the expected proper graph, with no duplication:
For other people facing the same issue.
I'm not sure why it happened but it was caused by the tags created using the git-graph extension in VSCode.
To fix this: manually deleted all tags locally only and then fetch them back using git fetch --all --tags.
Note that if the tag was also pushed separately (possibly create/push by another collaborator), a git fetch --tags would bring it back.
While it was not the case for the OP, the command "Git: Delete remote tag" can help, and is introduced with VSCode 1.75 (Jan. 2023) with PR 170415 from the 2020 issue 104845.
This is available in VSCode Insiders today.

How to updated deleted files on Github

I'm working on a project in Rails and was using a CSS framework that came with some images. I later decided to use something else and no longer need the images. I deleted them, committed my changes to github but now every time I I commit to github it pulls the files I already deleted. How do I keep it from doing that? I want those changes gone for good, not readded to my project every time I merge.
After committed have you push your change to repository. Please do following
delete images
git status
You will see files changed are comming in status, if images comming than go head and continue, you can either run git add . to add all files or
git add images_name_or_folder
git commit -m "Removed images"
git push
Now check and do `git pull` to check if all images gone.
I fixed this by doing a force push. I don't understand the problem but I forcing the push fixed it.

on git pull asking to commit the local changes

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.

github is not the same after push

I'm wondering how this is possible.
I made quite a bit of changes to my rails project (deleted some stuff, edited files, added files, ...) as I implemented a whole new design.
And now I want to commit my project and push it to github
git merge new-view
git add .
git commit -am "implemented the new design"
git push origin master
Now when I pulled the changes on another computer I noticed that not all of my features were working. (for example the image slider wasn't functioning).
When I go trough the files, it looks like all the changes I made are there, but I must be missing something because both projects are not behaving in the same way!
Even when I clone the project again from github (on the original computer with the working projectfolder), the feature still doesn't work.
git clone projectname
Now in my old folder I can't push any other changes as status tells me that my branch is up to date with origin/master
git status
I figure that I can just delete the github project and upload it again, but that's obviously not the way this is supposed to be done.
Any ideas what could've gone wrong?
Make sure that no important files are being ignored- see this answer
Make sure everything is truly committed. git status and git status --cached
Make sure any databases are initialized, migrated and populated with the same data.
Check browser caching.

git pull says config/environments/development.rb is not committed

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.

Resources