rails server not serving git files of current branch - ruby-on-rails

I setup a rails project and started working in a specific branch (branch1). I was doing ok with rails s until I wanted to setup another branch (branch2) with different files. I did git fetch origin branch2 for getting the second branch, and was doing fine configuring this branch (bundle, rake db:setup, etc...) up until running rails s. When I start my server, it should serve the files of my current checkout branch (branch2) but it serves the files of the previous branch I was working on (branch1).
Things I tried:
Thought git fetch won't actually get the remote branch to my workspace for the server to load up the correct files. So I deleted the fetched branch and did git checkout -b branch2 origin/branch2. Server still loads files in branch1.
Did spring stop so the server don't load up files stored in the cache (I was told this... I don't really know how spring works). Still, server loads files in branch1
I cloned the repository again, and set up everything for branch2. But still rails s manages to load branch1 (I would say that branch1 is the default when you clone the repo)
What I expect:
Doing rails s in checkout branch1 should load and display app in branch1.
Doing rails s in checkout branch2 should load and display app in branch2.
Any help would be really really REALLY appreciated, I've been stuck with this for hours now... thanks in advance.
P.S. The branches share the same database, I don't if that would help but I thought it was worth mentioning

Thanks for the help on the comments, unfortunately those answers didn't work for me.
Turns out, the server was loading the app correctly in localhost but because the navigation menu on the project is too big, it was saved in the cache to optimize the load in every branch. So I needed to run a script for changing the navigation menu (the script was provided to me by my colleagues that were in the project long before me).
So if you have this problem, ask your colleagues, contributors, boss if there is something you are missing.

Related

Capistrano: How can I leave a git repository on live/deployed

Ok, Using capistrano 3.2 with Rails 4.2.
Put simply I want to have each release on the live server to have an intact git repo with it. I know Cap uses git to clone the files but afik it deletes the .git folder by default. I swear I had this working before on earlier versions of Capistrano but no amount of Docs or Googling is finding the right setting. Or if I had an odd version of Cap
And before I get jumped on with "Version control on live? Never make changes to live, develop on your dev server you idiot!?"
Having an active git repo on live is invaluable if something changes out of your control, or if there is an emergency you have no choice but to monkey patch. Because now you have the change shown up by git and you can commit it, and push it back into your central repo and have it go up stream neatly. Its saved my ass before and means I don't have to copy by hand what I know has fixed the "live" issue.
Anyway, justification over. Anyone know how?
I apologies for the simple question, I think it's unlucky google fu which has left me without an answer from searching for this. Searching "Capistrano leave git on live" or other such terms are swamped with using git to deploy.
Cheer in advance.
This would be non-trivial. Capistrano uses git archive piped through tar to create the release folder. Hypothetically, you could override the task which does this, but you would probably spend more effort than it would be worth. I would highly recommend that you look at just creating a workflow where you commit a hotfix and push again. We use a prod branch at which the production deploy points, thus you could commit the change to the prod branch and cap production deploy, then merge your change back down to your development branch.
If you do choose to try and override this, look at the Capistrano source for the git tasks. It uses the Git Strategy class, so you would need to subclass and override it, then override the task to use your class. Capistrano is basically just a subclass of Rake, so look for documentation around overriding a Rake task, e.g. Overriding rails' default rake tasks.
Good luck!

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.

Rails keeping git versions correctly

I hope this is an ok question for StackOverflow. If it isn't, let me know. Thanks!!
I have my first Rails app about to go production. I'm using GIT and Github for version control. And I'm using CAP to deploy to our own servers.
We have one server for Staging and one for Production.
So, lets say it's day one of production. And I'm also coding new features on my iMac. So, I'm making changes and saving to GIT, Github and staging.
But, then the users run into a small error that I need to make a quick fix on production.
Well, I've already started making major changes to the code and I don't want to put that into production.
How would I make the quick fix the users need?
Thanks for the help!
Ill assume you have a prod branch and a devel branch, and the tip of prod is what has been released to prod.
You can;
1. git stash all your current work if you havent committed it yet.
2. git checkout prod
3. Create a new branch for your hot fix, fix it, merge it back to prod and release it.
4. git checkout devel and git stash apply your stash if you need to.
5. git merge prod into your devel branch so it has the hot fix you just deployed.
If you dont have separate branches for prod and devel, now might be a good time to set them up :)
See the section 6.3 Stashing of the progit book.
http://git-scm.com/book
You may create a branch for fixies, fix a bug there, and update your application on production server with this branch. In some moment you will merge them (branches).

GIT deleted my local files

I have a pretty big problem. I am going through a Ruby on Rails tutorial, and they have suggested that I use GIT for version control. I have never used it before, and through the tutorial I don't think I used it right. Here is some back story.
I created a new project, and then I created a new Github repository. I named them the same thing, and I pushed my project to that repository. I then looked at Github, and all of my project files were there. I then went through a few chapters of the tutorial, and followed there instructions for pushing files to GIT. After awhile I realized, that none of my files were being uploaded. I didn't really care, so I went on with the tutorial. Still pushing files to GIT even though they were not showing up.
IMPORTANT
My Github repository only had the few files from when I first created it, the project on my local machine has a MANY more files. In the last chapter of the tutorial I was able to follow, it told me to do these commands:
$ git add .
$ git commit -m "Finish layout and routes"
$ git checkout master
$ git merge filling-in-layout
Once I did those commands, my project located on my local machine lost ALL of the files I created in the last couple of days. My guess is that Github replaced my files from my local machine with the files on Github (Just the files created when I started the project)
I think I have been adding files to GIT on my local machine since the folder '~/.git/logs/HEAD' has all of the commits I made, with what looks like GIT file numbers.
Any help would save me so many hours.
Thanks, -Chris
You committed some changes, then got the old version and reverted to it by issuing "git merge filling-in-layout". (you created a branch "filling-in-layout")
whatever you do DO NOT -> git reset --hard <- DO NOT.
what does "git branch" say?
do this:
git checkout master (or one of the others)
and look which one is yours. ;)
Erase github from your mind. It is irrelevant. The git repository is on your machine, inside your rails app folder. That is the beauty of git. So everything you have ever committed to git while working from that folder is there. It's possible you made some mistake along the way, or that the tutorial instructed you incorrectly, but you can look through all your commits with "git log", and then just go back to the point where things were good: checkout that commit (thus recreating the situation as it was at that moment), and pick up again from there.
Pedagogically I would suggest that you not try to learn git and rails simultaneously. They are both big and interesting, but they are completely orthogonal (that's fancy talk for "they have nothing to do with one another"). If you want to learn rails, learn rails. If you want to learn git, learn git. Just a suggestion.

Published using capistrano, is it possible to know which version is running using GIT? or anything?

I pushed code to my server using capistrano (using git also).
I then made changes on my laptop, but haven't sinced published to the server.
I want to know which git version I pushed to the server so I can rollback to that version.
Is this possible?
I know I should have used tags but kinda late for that, hoping I can figure out the version I pushed to my server, so I can rollback to that version or at least diff from that version to the current built to see what has changed since then.
Capistrano should have put a REVISION file under #{your_app}/current on the server, with the deployed commit's SHA:
So something like:
git diff `ssh your_user#your_server "cat /path/to/your/app/current/REVISION" `
should get you the appropriate diff.
yes, you can check your reflog.
git reflog
But you should be tagging when you release.
Hope this helps
git fetch
git log origin/master -1
fetch synchronizes with your server and log origin/master shows the log of your server's git repo instead of your local repo. The -1 tells it to only show the last commit. This will show the commit hash and message of the last commit on your server's repo.
If your server is listed in your remotes as something other than origin or your server is using a branch other than master, you'll have to change that. But "origin" and "master" are the defaults and are standard convention if you haven't changed it.
<subjective>
Unless you're explicitly versioning your software (like when creating a gem, for example), it's not necessary to add a tag every time you deploy your app. This would quickly become unwieldy. With git, a commit hash can be used just like a tag if it's ever needed.</subjective>

Resources