Github pulling does not work in - Rails 5 - ruby-on-rails

I'm trying to pull last commit that I made on github, and though I get no errors, I see no changes in the code. I messed up my schema file, but after I pull the code it does not change at all.
I searched here on stack and the solution that worked for others didn't work for me, and this is also my first time that I'm pulling code from github, so I could've probably done something wrong.
I used this code:
git fetch origin controller-generator
git git reset --hard FETCH_HEAD
This is what I get as the output
HEAD is now at 1fb8c97 Integrated friendly routes gem
'Integrated friendly routes gem' is my last commit that I want to pull, but nothing changes. I don't know if I need one more step or whatever it goes with it.
This is what I have in commit db file
And when I pull this, I get this
The last one should not be there.
This is output
equalsign:~/workspace/BlogAndPort/db/migrate (controller-generator) $ git reset --hard 1fb8c97d64f389904b3048fb2850fcfd8425cd36
HEAD is now at 1fb8c97 Integrated friendly routes gem
equalsign:~/workspace/BlogAndPort/db/migrate (controller-generator) $ git push -f origin HEAD
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
Everything up-to-date
The problem is still the same as shown in the pictures. db files did not change

If I understood, you are asking to reset your local/master with origin/master.
$ git fetch
$ git reset --hard origin/master
You can back (hard reset) to a commit that was working for you.
$ git reflog # copy the commit-sha where you want to back/reset
$ git reset --hard <commit-sha> # reset to the commit
Now, if all things are ok. Then Force (-f) Push to remote.
$ git push -f origin HEAD # update remote branch

Related

Git push failed when I updated the cocoaPods

In order to fit iOS 10,I have to update these 3-part in cocoaPods,so I had updated the cocoaPods to it's newest version.APP works fine,but when I use git push, the terminal require me to input username and password for github,however,the terminal showed:
fatal: Authentication failed for 'https://github.com/CocoaPods/Specs.git/'.
I am sure the username and password I put into is right.
Before I asked this question here I had ask for help on Google and find a solution:Pull first,then push.
But the embarrassing thing is that I had commit my code.That is to say,if I use git pull I will lose all my work today,that's terrible,so I wonder if there any better way to solve it.
When I hit git remote -v in terminal there showed something interesting:
origin https://github.com/CocoaPods/Specs.git (fetch)
origin https://github.com/CocoaPods/Specs.git (push)
I am surprised about how cocoaPods changed my project's remote url?
Finally I use git remote set-url origin xxx solve this problem.

Ruby on Rails tutorial chapter 1.4.3 (part about bitbucket)

I'm having some trouble setting up the bitbucket repo
humantoast#rails-tutorial:~/workspace/hello_app (master) $ git remote add origin git#bitbucket.org:HumanToast/hello_app.git
fatal: remote origin already exists.
.
humantoast#rails-tutorial:~/workspace/hello_app (master) $ git push -u origin --all
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I just want to say that I tried the following and it seems to have worked. Note that '<username>' refers to your username. If on a numbered list, replace <username> with your username.
Enter the numbered commands below into the terminal. 'Result' is the output the terminal showed after the command was entered
git remote -v
Result
origin git#bucket.org:/hello_app.git (fetch)
origin git#bucket.org:/hello_app.git (push)
git remote rm origin
Result
No output in the terminal
git remote add origin git#bitbucket.org:<username>/hello_app.git
git push -u origin --all # pushes up the repo and its refs for the first time
Result (note the 3 dots below refers to output on the terminal that I excluded due to it potentially containing confidential information)
.
.
.
Are you sure you want to continue connecting (yes/no)?
yes
Result
.
.
.
To git#bitbucket.org:<username>/hello_app.git
[new branch] master -> master
Branch master set up to track remote branch master from origin.
That seems to have done the trick. I wasted a day stuck so early in the book.

Cleaning Git Repository: Rails Project, added Gems to Repo by mistake

I was trying to solve an issue with some gem conflicts, and I added all of my gems to vendor/cache, I have since removed them, but now I have a 40M pack file where it used to be less than 1M.
I have tried to filter the branch
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch vendor/cache' --prune-empty -- --all
This goes through a list of rm commands, for example:
rm 'vendor/cache/sass-3.2.8.gem'
and then at the end
Rewrite 9c90286ba515f46919e82e73e2c01a5db1762668 (202/202)
Ref 'refs/heads/master' was rewritten
Ref 'refs/remotes/origin/master' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged
Finally I run
git gc --aggressive --expire=now
But I still have the same huge number of objects, and the pack file is still 40M. I even try forcing a push when this was complete with no change. Any idea how I can clean up my repository following this mistake?
I think you'll find the answer at the bottom of the question or in the accepted answer here:
Remove file from git repository (history)
The key is in that warning line you have:
WARNING: Ref 'refs/remotes/origin/master' is unchanged
The solution discusses how to get rid of that so that the other steps accomplish what you want and reduce the size back down.

Change github repository for Rails

How do you change the git repository a rail app is pushed to? I know that this is possible because I did it a few weeks back.
Basically I have two very different versions of a app on my local machine. I would like the initial app to still point to the old repository. However, the new version needs to be placed in a completely separate repository.
When I run git init in myapps/old_app/ it puts Reinitialized existing Git repository in /Users/jamespollard/rails/old_repository/.git/
AND
When I run git init in myapps/new_app/ it puts Reinitialized existing Git repository in /Users/jamespollard/rails/new_repository/.git/
However, when I try and git push anything to the repository, it still goes to the old_repository.
Updates
If I enter $ git remote origin set-url git#github.com:mygithub/myapp.git
I get
error: Unknown subcommand: origin
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote rm <name>
or: git remote set-head <name> (-a | -d | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
or: git remote set-branches <name> [--add] <branch>...
or: git remote set-url <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>
-v, --verbose be verbose; must be placed before a subcommand
If I enter $ git remote set-url git#github.com:mygithub/myapp.git I get the same error message as above (minus the origin error). In either case, if I run git push origin master it still pushes to the old repository. I've tried adding the new repository again with the same name, but I get a error (which i would expect) saying that it already exists.
Create a new repository in GitHub for you new app, if you haven't already. Make that new repository as origin to your new repository:
git remote add origin <github_url>
If the remote already exists, you might have to git remote set-url origin <github_url>
Now, push to the repo.
I ran into a pretty similar situation few months ago. On the new version of the app there is a .git folder (which was also copied along with all other files when you copied the app). Heroku needs the information from .git to see if anything has changed. So when it 'reinitialized', heroku thinks its the same app.
So here's what I did that resolved the problem.
Copied the entire app folder.
Changed app name wherever they appear (mostly in config folder, google it for a list)
Chang secret.yml file (get a new key by rake secret) or secret token if older version
of rails.
Most importantly, there should be a .git folder in your app folder (it maybe hidden).
Delete that .git folder (it contains git info of the old app)
Initialize a new git, git init
and then commit and push.
Your new app should be a separate app now.
I think this might work if on heroku, worth a try:
git remote rm heroku
git remote add heroku git#heroku.com:yourappname.git
or you can try this
1). open a terminal
2). Go to your_app_directory/.git/config
3). Once you open the config file then edit as follows:
Change
url = git#heroku.com:old_app_name.git
to
url = git#heroku.com:new_app_name.git
Obviously substituting your apps old name to its new name. Hope it helps
If you take a peek at your .git/config file, you see / check that the url is still pointing to the old remote
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = <old_github_url>
so you wish to keep the old remote. let's call that oldremote.
First thing you can do is the rename the remote with :
git remote rename origin oldremote
Now you can add the new remote with :
git remote add origin <new_github_url>
From now on, pushing normally with just git push will push to the new remote. git push oldremote SHA to push to the old remote
remote reference : http://help.github.com/remotes/

Ruby on rails and Heroku problem

$ git push heroku master
I basically get this error message.
error: src refspec master does not match any.
error: failed to push some refs to 'git#heroku.com:falling-stone-505.git'
I'm very new to computer programming and ruby on rails so an "idiots" guide to solving this would be appreciated.
Thanks in advance.
You haven't committed anything to push yet. Try doing:
$ git add -A
$ git commit
Then try to push to Heroku again.
You might try following along with this tutorial, although I can't vouch for it. Most of the professional endeavors in this space are books.
If you want your commits to be easier to track in the future, after
1.
$ git add -A
2.
instead of
$ git commit
you can use
$ git commit -m "add a message here such as FIRST COMMIT or PROBLEM WITH CONTACTS VIEW ADDRESS VARIABLE TYPO FIXED."
3.
Then you can
$ git push heroku master

Resources