git heroku not download collaborators recent push - ruby-on-rails

A collaborator on a heroku app Im working on pushed some code, moments before I made a push, as the owner I rolled back the app, but now I can not seem to download the code to the my local repository?
I've tried rebasing the branch, fetching and reseting the HEAD, everything said it is up todate? I even deleted the whole local repository as a last resort and clones the app, is rolling it back in Heroku causing the problem?
When I do heroku releases I try to git checkout <deploy of collaborator> and I get a pathspec error

can`t you see his commit in reflog (git reflog)? if it is the case ask him to push again or push to a feature branch and cherry pick the commit you needed in to your branch

Related

Heroku rollback and pulling older release

I did a mistake in the code and pushed it in to heroku master. I am not able to identify the problem in the code I have locally. I did a heroku rollback to previous version - it worked and previous version is visible on heroku.
However I am struggling to pull the code (as heroku clone:app name gives me an old code). I tried heroku releases to get the release number which I then used for git pull heroku af5c366b, however getting err:
fatal: Couldn't find remote ref af5c366b
How can the code be restored?
I am completely now to Heroku.
You should be able to simply run...
$ git checkout af5c366b
Which should bring you to a "detached head" state with this helpful message..
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
Once you checkout the branch you can merge that branch into master.
$ git checkout master
$ git merge new-branch-name

Git: force push cleared all of my commits - can I get them back?

My live site was updated since my last commit, and I hadn't made any local changes, so I wanted to just push everything that's live up to my Git repo.
So I did a git push --force
Now I have no commits in my repo, other than the most recent commit.
How can I get them back?
Here's the repo if you need the link: https://bitbucket.org/nicolefurlan/us-vegweek-2014
I'm not sure which repo was pushed to where, but on any repo (local or remote) you can run git reflog to get the history of all previous commit states in that repo.
Use git reset --hard <commit-id> to restore the last good commit to master.
If your last good state wasn't committed at any point in time, there's no way to retrieve it.

Trouble pushing changes to remote Git repo

I have started learning Ruby on Rails and Git.
Whenever I try to push any changes to my remote repo on Github, I encounter the following error:
C:\Sites\first>git push origin master
To git#github.com:piy9/Twitter_clone.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:piy9/Twitter_clone.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
NOte: I have added all the files in the directory and committed the changes. I have not created any separate branches using pull or checkout.
I am not asking for a solution to the problem.
doing
git push -f or
git push origin +HEAD
worked for me.
What I want to know is, why am I getting the error while trying to push to the original branch.
follow this and get everything works....
git branch production
git checkout production
#do some code changes
git commit -am "some desparate code changes to try fix heroku"
git push heroku production:master
Note: this will get your work done and will leave your previous branch.
or you can try this one also git push heroku +master
Looks like remote branch is ahead of yours, which means it contains something your local branch does not have. You may easily see commits on remote branch since when local branch was created or updated (assuming you run "git fetch origin/master" to fetch remote changes first):
git diff HEAD...origin/master
The output will answer your question why you are getting the error.
Now, my guess about the reason of the problem you have is that either someone has access to remote and pushed something, or you modified something using github editing interface and committed since last checkout/pull/merge. Using forced push as you did is not a good approach and it messes the history, it basically overwrites the remote branch with your copy, ignoring any remote changes.

Working with Git branches

I have a Rails app deployed on Heroku and I have a git repo that I'm currently working on with uncommitted code changes. In the meantime, I need to make changes to the source on Heroku independently of the local repo. Can I do the following:
Clone the Heroku git repo on the same development machine with a different app name though with the same account
Make changes to the new local repo
Commit those changes to the new local repo
Push those changes to the Heroku repo
Resume working on my original local repo
Will this approach work?
Yep, that workflow would work, or stash them - and don't forget if you do make a clone of the heroku repo you'll have made changes to a different clone of the repo and you'll need to make those changes in your original local repo.
In future I'd suggest that you assume that your 'master' branch is what's live on Heroku and branch of that to work in - you can even push this branch into a new app for testing purposes. This way bug fixes can be performed on your local master branch (or another branch and merged into master) and pushed to heroku and then when you've finished your new work you merge the branch back into master and deploy that to your live environment. I wrote a blog article on the subject a while back, here
I haven't used heroku but if I wanted to make changes to a deployed application while I had unsaved changes in my sandbox, I would do one of the following.
stash my local changes, cut a branch from the point where I want to make a fix, make it, deploy it, switch back to my original branch and pop from the stash.
Commit my unsaved changes (into the current branch - say work), cut a branch from the point where I want to make a fix, make my fix, deploy it, switch back to work, reset my HEAD to before my "temporary" commit and resume work.
Unless you're using git in an unconventional fashion, there's no need to make another clone.
If you clone the heroku repository to a separate directory, made changes and push it from there, then there is a possibility of conflicts later down the road.
If its only the issue with the uncommitted changes then certainly you can stash them using "git stash" and later retrieve it using "git stash pop".
My work-cycle: I always keep a master branch with the #1 rule "always push to Heroku after committing something to master". If I code on something that I do not want to deploy immediately, I have to branch.
I know this works not for all use cases, but having always a branch that is identical to the app that is productive on Heroku makes me sleep better ;)

Is there a way I can view changes committed to my local GitHub branch without having to push it to the master branch?

I'm still figuring GitHub and Heroku out, so please bear with me. :)
I've a web app on, say, xyz.com. What I am doing now is to make some code/UI changes on some files, commit those files, push them to the master branch, and then refreshing the url to see these changes.
I think this is obviously the wrong approach, but I don't know of how else to test changes done to my code without having to push them on to the master branch. How could I do so?
I don't quite understand the situation in the full version of your question (see my comment and, as icc asks, why can't you test locally?), but to answer the question in the title, you can see the differences between your master and the version on GitHub by running:
git fetch github
git diff github/master master
(That's assuming that the remote that refers to your GitHub repository is called github - it might well be origin in your case. You can see all your remotes with git remote -v.)
To explain that a little further, when you run git fetch github, git will update all your so-called "remote-tracking branches" - in most cases those are the ones that look like origin/whatever, github/experiment, etc. Those are like a cache of the state of those branches, and they're only updated when you run git fetch or successfully git push to that branch on the remote repository. So, once you've done this to make sure that github/master is a recent snapshot of that branch on GitHub, you can happily compare it with your local master branch using git diff.
First: You don't push to the master branch, you push to a remote repo. You should probably read up on your git.
Second: This is not a good workflow, first you should commit your changes and then test them locally. When you are done testing you are ready to push your commits to a remote repo.

Resources