Deleted github branch. but rails generated controllers remained in Master? - ruby-on-rails

I am kinda new to programming. I might have not typed the right keyword but I couldn't find anything that would answer this questions. Also GitHub tutorials didn't cover this (as far as I saw).
So installed rails Device gem and everything was working nicely. branched out to user-sign-up-mailer. I decided to experiment with Device controllers. so I $ rails generate devise:controllers confirmations.
I did stuff there and totally messed my app up. anyway I decided to delete the branch. I checkouted out to master and deleted branch with $ git branch -D user-sign-up-mailer
to my surprise the controllers I generated in branch are in my master. now I feel like I have to reverse that.. but my question is what did do wrong? why did these controllers come to master from? here is the flow from the terminal
so how to i reverse that and Destroy only device controllers?
Mac (user-sign-up-mailer) $ rails generate devise:controllers confirmations
Running via Spring preloader in process 19574
create app/controllers/confirmations/confirmations_controller.rb
create app/controllers/confirmations/passwords_controller.rb
create app/controllers/confirmations/registrations_controller.rb
create app/controllers/confirmations/sessions_controller.rb
create app/controllers/confirmations/unlocks_controller.rb
create app/controllers/confirmations/omniauth_callbacks_controller.rb
Some setup you must do manually if you haven't yet:
Ensure you have overridden routes for generated controllers in your routes.rb.
For example:
Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions'
}
end
Mac (user-sign-up-mailer) $ git branch -D user-sign-up-mailer
error: Cannot delete the branch 'user-sign-up-mailer' which you are currently on.
Mac (user-sign-up-mailer) $ git checkout master
M app/models/user.rb
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Mac (master) $ git branch -D user-sign-up-mailer
Deleted branch user-sign-up-mailer (was bdd7590).
Mac (master) $ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: app/models/user.rb
Untracked files:
(use "git add <file>..." to include in what will be committed)
app/controllers/confirmations/
no changes added to commit (use "git add" and/or "git commit -a")
Mac (master) $

By the looks of it you never added or committed the files to your branch. Which means git doesn't know about them. That is why they are still on your master branch.
You should be fine to delete any of the files listed as untracked, and then you can do a $ git reset --hard to remove any of the changes since you last committed your changes.

You can destroy anything you generate by replacing 'generate' with 'destroy' like so:
rails destroy devise:controllers confirmations
Also, this site helped me a lot when getting started with Git. When switching back to the master branch after you merge changes, be sure to do a hard reset (replace local changes).

Related

Filetree is not refreshing after switching branches - cloud9

In cloud9 IDE, I am doing simple rails app in master branch. I decided to experiment a little, so I created new branch like this:
git checkout -b experiment-branch
Then I created some controllers, models etc. but experiment fails and I do not committed it. However I dont't want to delete this branch, so I tried to go back to master:
git checkout master
and code (controllers, models etc) from the previous experiment was still there in filetree, ApplicationController etc.
I tried git reset --soft <desired-previous-commit-hash> but it not worked.
I assume the second command should return me the state of my app from before creating the branch experiment-branch. Am I right or I do something wrong?
If you have not tracked the new files you add in the experiment-branch - these are still lying around as untracked files.
Untracked files are not removed when you change branches.
You would need to clean them to remove the untracked files. use git clean -n (dry-run) to identify all the files that are untracked.
Then you could git clean -f to clean all the file shown in the dry-run. Or you could use the interactive mode git clean -I
To revert changes from tracked files, use git checkout .
Refer this post for more details.

Git shows "Everything up to date", but I can see gem files updated in my local, not updated in git

I am building a rails application and I'm very new to Git. I am trying to update files in git, and although my local gemfile has been updated, when I try git status, git add . or git commit everything shows up as "Everything up to date" and "nothing to commit, working directory clean"
I am using Vagrant on windows
Have you tried git pull origin master and then git push origin master
Note: check if you are on your on your main branch "origin master" by typing git branch -a and then try the above logic
you should see below message on trying git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
I was able to figure out the problem. I have been commit'ing from a different folder, where as my actual app existed within the root and was not at the root.

Ruby on Rails - Git Branch Workflow

I know its a simple concept but just not grasping it after researching several sites.
I have a Ruby On Rails project and using git to manage the source. I have a production ready snapshot and initialize git such that it has a master (with git init, git add -A and git commit -m).
Now I want to try out a new feature so I create a branch called 'test' with git checkout -b test
Now while in test I try out a new scaffold with rails g scaffold UserToken username:string
Scaffold created all of the ROR files and I do a rake db:migrate to update the DB. I then go into the rails console and test out adding records to the db and then start working on updating the other generated scaffold model file.
After lunch I come back and decide I want to scrap all of this.
Questions - (after trying this out myself) is the only way to get back to master is to git add -A, git commit -m and then git checkout master ? Do I really have to add and commit to get back to master? (this does work; however I don't think I'm grasping something basic in git that I would do a commit on something that I am going to scrap)
Next, if I do the above (again I don't think that's right) when I get back to master I do see that my scaffold files are gone as are the migration file (which created the table) and the schema.rb reflects that the table generated while in the branch is not there.
So far so good:
HOWEVER, if I go into the actual database the table IS still there. What basic fundamental am I missing in ROR/Git of testing something out in a branch and then abandoning it?
UPDATE #1
So Stash does not appear to help:
Stash does not help.
Steps:
rails new test_app
git init
git add -A
git commit -m 'initial commit'
git checkout -b newfeatures
rails g scaffold UserToken username:string coin:integer
files get generated...
sqlite3 db/development.sqlite3 show that there is now a table called user_tokens:
git stash save
git checkout master
Now in Master however all of the scaffold files still exist (and shouldn't)
You have two questions here:
First: How do I move between branches without commiting work in progress?
To move between branches without having to commit your work you can use git stash.
git stash help
Usage: git stash list [<options>]
or: git stash show [<stash>]
or: git stash drop [-q|--quiet] [<stash>]
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] [<message>]]
or: git stash clear
Once you stash your work then you can switch between branches without problem. Note that files that you wish to stash must first be added to a git branch via git add. Changes to files, including creation, that have not been added to git are are not tracked. So they are just like any other part of the general file system and will remain visible across branches.
Second: Why do my database migration changes in one branch show up in another?
Because the Database manager is not part of git. Whatever DBMS you are modifying those changes are persisted through the DBMS. If you want to keep your branch migrations separate then you need to have a separate database instance for each.
It may help if you imagine a git branch as a file-system template. When you switch to another branch then that branch's template overwrites your existing file-system with whatever is under its control. Everything else is ignored. When you commit you are updating the template for that branch. However, all of your work is actually done in the one true file-system.
What this means that things that you do to the file-system that are outside of git's control remain visible from all branches.
git reset --hard HEAD deletes everything and goes back to head in your testbranch so you can easily switch back with git checkout master
rake db:reset should do the trick with your data in the DB
UPDATE:
If you really want to get rid of anything:
git reset --hard && git clean -dfx
rake db:drop
rake db:create && rake db:migrate

After cloning a git repo, Xcode says it can't contact the server when I try to update

I created a git branch called bugfix/development and cloned the branch and opened the project in Xcode 5. After making some modifications, I tried to Commit my changes and Xcode said it could't access the repository.
When looking at Xcode preferences, the repository was online in the Accounts area.
What could be causing this?
The "/" in the branch name was causing problems with the Xcode/git integration. After renaming the branch from bugfix/development to development, the Xcode/git integration worked great.
Here is how I changed the branch name:
$ git branch development origin/bugfix/development
$ git push origin development
$ git push origin :bug fix/development
Then,
$ git fetch origin
$ git remote prune origin
and now I can see the new branch. All users would need to perform the last two commands in order to see the change.

rails destroy model command not visible in git

Just starting out with rails and git and have run across an issue where I had generated a model, however just for a start have decided to use scaffolding for my first attempt. In this case I ran the following command
rails destroy model company
I am working in a dev branch I have created, after running the above command i checked my repo with git status and it said that there were no changes to commit. I checked that my model.rb file had been removed, so switched to my master branch and ran the command:
git merge dev
however it says that everything is up to date, even though I have changes in my dev branch which doesn't seem to have registered in my git repo.
Have I done something wrong, or is there something I am misunderstanding with rails to do with the generate and destroy commands?

Resources