Can't git revert to older commit right after clone (no changes made) - git-clone

I need to test an older version (commit) of some code from github. I made git clone and then
git revert $id
where &id was id of the version that i need to check. I got this error:
error: could not revert 9a0d90d... Version 1.2.1
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
I made no changes to any files after clone.
What am i doing wrong?

If you any to test an older version, you should create a branch directly from your older id
git checkout -b test $id
git revert tries to compute a new commit which would cancel changes introduced since $id. Conflicts can occurs when computing the negative merge.
You don't need that for consulting/testing an older revision.
And if you need to make any changes in the context of that test, you will already be in a 'test' branch.

Related

Git pull request - how to pull and update Sublime

I've made a stupid error which has messed up my database on a Rails App I'm working on. Luckily I'm on a branch and haven't committed any changes so the version on Git is in working order.
How do I now pull through the Git version and update to Sublime so I can carry on working as if nothing happened?
I've just done git pull origin master but it says up to date so I've obviously done something wrong.
I'm not keen on a db:drop so I'd rather do it this way if possible.
You can't pull again, because you already pulled every commit from your remote.
Add changes, stash them, remove the stash:
git add --all && git stash && git stash drop
This will remove every uncommited change and bring you back to the latest commit on the current branch.
git checkout 01h5y77d (find this in git, a version of the app which works)
This would print "HEAD is now at 01h5y77d..."
You don't have to commit because you did not commit the mistakes yet :)

Git merge conflict with workspace.xml

I'm trying to push my Rails project to Heroku, but Git isn't allowing me to do anything at the moment. Here's what I've done so far:
git push heroku failed because the heroku branch was "ahead" of my local branch, which should not have been possible.
I pulled and there was a conflict with .idea/workspace.xml. I wasn't able to find out what that file is, but it's huge and Git wrote all kinds of garble to it. Too much to manually "resolve" conflicts.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
I ran git add -A (also tried git add . and git add)
git commit --amend fails because "You are in the middle of a merge"
git merge --abort fails because "Untracked working tree file '.idea/workspace.xml' would be overwritten by merge (despite the fact that the file has been moved)
git reset --merge fails for the same reason.
How can I make Git work again?
.idea/workspace.xml
This file is your idea workspace files. They are generated by IntelliJ tools.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
Simply add the folder to your .gitignore but since its already committed you will have to remove it from the repository:
# Quit the merge
git merge --abort
# remove the whole folder from the repo
git rm -rf --cached .idea/
# add it to the .gitignore: idea/
# add and commit your changes
git add .- A
git commit -m " Removed idea folder"
git push origin <branch>
If you still unable to do it?
First reset the code to the previous state and then do the above code again.
The reset will take you to your last commit before the pull
git commit -am "message" worked (as opposed to amending a commit)
I have resolved a similar problem by simply deleting the workspace.xml file. By building and running the program again idea will autogenerate a compatible file.

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.

GIT confusion with restKit

So i am learning to ever so slowly use git to get me the latest update of RestKit as the old version has retain cycles...fair enough HOWEVER, when i pull using the gitHub Client it does not give me the AFNetworking files, which i was then told use the command
git submodule update --init --recursive
which i do, problem is that i noticed that after running that i run
git submodule status
It has taken me off the master branch and put the HEAD back in thus reverting me to old stuff. and hence back to leaks and stuff.
So i thought maybe i could install using cocoapods or perhaps put a submodule within the restkit submodule for AFNetworking...all did not seem to work and now i have followed this guide How do I remove a submodule? up until the last step as i dont know what committing will do? i hope it does not commit the fact that i deleted everything onto the restkit site? i am so confused, initially all i wanted to do was switch the current branch submodule i have to the master.
Assistance would be much appreciated.
EDIT:
Okay as to answer what Commit does, commit only affects your copy of the repository and will in no way affect the remote "main" repository everyone else gets their code from, so in essence i was able to commit it, then run a brand new submodule from the branch i wanted, But the question still remains Is there a way to switch the branch you pull your data from when using the update with --recursive?
Simply go in th e RestKit directory and type:
git pull origin master
(if you use the master branch of course)
Also, if you need to update all your submodules, just go to the root of your project, and type:
git submodule foreach git pull
git submodule update is confusing, here what it really does:
When you invoke git submodule update it looks in the parent repository for a SHA for each submodule, goes into those submodules, and checks out the corresponding SHAs.
As would be the case if you checked out a SHA in a regular repository, this puts the submodule into a detached HEAD state.
EDIT
To switch branch of a submodule simply, let say 'development', simply do in the submodule git checkout development and then you should be able to do git pull origin development

git - update to new branch of rails

I currently have a rails project running of a git tag v2.1.2, to get here id did
git checkout v2.1.2
However there are now new fix's that have been applied to the 2.1 branch, how do I move to this branch rather than the tag?
If I understand your question correctly, you have a tag and a branch named the same. Then, to checkout to the branch, you would provide the path to it.
For example:
git checkout refs/heads/2.1
This disambiguates 2.1 branch from a tag named 2.1 itself.
You can create a new branch that tracks the remote 2-1-stable like so:
git checkout -b 2-1-stable origin/2-1-stable
Then just cd back to rails root and commit the submodule change.
Later if you need to update it, you should just be able to cd back into vendor/rails and:
git remote update
git rebase origin/2-1-stable
And commit the changes again.

Resources