Reputation: 2087
Although I have read some basic commands on Github, but while following an open source projects developers configuration, I accidentally created something and got stuck so badly that now I cannot proceed to any place from that point.
What I did is
The instruction said to create a branch, so I created a branch with git branch branch_name
Then the instruction said to pull from my origin repo with git pull repo_URL branch_name
this is where everything screwed up.
I got some error where it was mentioned the resolution was to perform git commit.
Now everything got hanged.
I am in my new branch. Cannot come out of that, So eventually cannot delete that. Also, when I type git status
On branch branch_name
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
new file: ../../.br.json
new file: ../../.gitattributes
new file: ../../.gitmodules
new file: ../../.jshintrc
new file: ../../.travis.yml
new file: ../../CONTRIBUTING.md
new file: ../../Gruntfile.js
new file: ../../NOTICE
new file: ../../package.json
and so on...
When I try to checkout some other branch by git checkout master I get these messages:
.gitignore: needs merge
LICENSE: needs merge
README.md: needs merge
error: you need to resolve your current index first
What is the resolution, How can I revert everything back?
Upvotes: 1
Views: 1239
Reputation: 3346
gut pull
is a short for git fetch
followed by git merge
There was a merge conflict!!!
Take a look at these files:
.gitignore
LICENSE
README.md
You need to resolve those merge conflicts first. See here.
If you have screwed up the things, you can abort the merge and do the merge again.
git merge --abort
git merge <remote>/branch_name
In case you do not want to keep any of your changes. You can always reset you branch to the remote's version by calling:
git reset --hard <remote>/branch_name
If you want to keep your changes then you need to resolve those conflicts. You are in middle of a merge and you cannot switch to master at this point.
Upvotes: 0
Reputation: 28180
Currently on your branch branch_name
you have some pending changes which prevents you from checking out the master branch
. To "recover" from that
you can either check in all those changes on the branch_name
branch or you can cancel out the changes.
With no pending changes you can switch to any other branch without any problems.
So the simplest way to check in all the pending changes is to run
$ git commit --all --message "Some messed up changes"
which will create a commit of all those changes. Even if you probably do not want to want to keep them you can always delete it later.
To cancel out the changes you can run
$ git checkout <filenames>
or to automatically process all files one of the following two commands
$ git reset --hard HEAD
$ git ls-files --modified -z | xargs -0 git checkout
By the way I recommend that you run gitk --all
to get a nice visual view of the branches and changes in your repository.
Upvotes: 1
Reputation: 1017
Open your repository on github web site. See if your branch exists there. by going to branches tab. If yes, go to terminal and do
git log
check if there is any commit shown which you don't want to push to your repo. You can view changes in commit by "git show " where hash is the id of commit shown in git log output. If there is no unwanted commit in git log output, just do
git reset
and you are good to go. If there was an unwanted commit to discard, which was not pushed to server, write the following command
git reset --soft HEAD^
and then,
git reset
Upvotes: 0
Reputation: 1274
If you want to revert back all the changes, just perform the following command:
git reset --hard HEAD
Upvotes: 1
Reputation: 1323333
Is there any way to do that?
Simply leave your current repo as it is.
Go elsewhere and try a different approach.
First make sure your config user.name
and user.email
are properly set locally.
Then clone the remote repo first:
git clone https://<yourUserName>@github.com/<yourUserName>/<yourRepo>
cd <yourRepo>
Once that is done, you should be in the master branch (check with a git status
, and a git branch -avvv
)
Finally, report the files you had created or modified from the old local repo to this one (simply copy), do a git add .; git commit -m "First implementation"; git push
.
Upvotes: 2