sisimh
sisimh

Reputation: 1337

how to fix git checkout command by mistake?

Hi guys I am new to git .

  1. I created a branch and commited my files on it .
  2. then created another branch (this one is the one i want to push) .
  3. pulled the first branch to the new branch .
  4. mistakenly did

    git checkout
    

instead of

git checkout "file"

Now when I type git status i get a message

nothing to commit

What can I do?

Upvotes: 0

Views: 1949

Answers (2)

Anthony Raymond
Anthony Raymond

Reputation: 7862

I think that you are missunderstanding commit and push.

A commit is like a pictures you are shooting with a camera. (you specifie what elements you want to add to this pictures with add).

When you have taken this pictures, it will stay in you album (where nobody execpt you can see it).

How to :
git add <path_to_file_1>
git add <path_to_file_2>
git commit -m "my commit message to describe what i had done"




A push is use to send you album to a repository.

How to :
git push <repo_name> <branchName>




When code is into a distant repository, it can be pulled to be merged with your code.

How to :
git pull <repo_name> <repoBranch>




What have you done.

As far as i understand, you have done the following sequence.

git branch my_first_branch
git checkout my_first_branch
..... working on your branch, modifying files .....
git add < all my files>
git commit -m "Hey this is my first commit"

git branch my_second_branch
# At this point, since you created your second_branch from first_branch, second branch contains all modifications made to first_branch, there are both the same.

git pull origin first_branch
# This should have failed unless you have push ????

git checkout
# this should have done nothing

Upvotes: 0

Suriyaa
Suriyaa

Reputation: 2286

You can revert to previous commit, ignoring any changes: git reset --hard HEAD.

Where HEAD is the last commit in your current branch.

If you want to get remote gh-pages branch: git reset --hard origin/gh-pages.

Upvotes: 1

Related Questions