简体   繁体   English

如何错误地修复git checkout命令?

[英]how to fix git checkout command by mistake?

Hi guys I am new to git . 嗨,大家好,我是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 现在,当我输入git status我会收到一条消息

nothing to commit 没什么可犯的

What can I do? 我能做什么?

You can revert to previous commit, ignoring any changes: git reset --hard HEAD . 您可以忽略任何更改而恢复到先前的提交: git reset --hard HEAD

Where HEAD is the last commit in your current branch. HEAD是当前分支中的最后一个提交。

If you want to get remote gh-pages branch: git reset --hard origin/gh-pages . 如果要获取远程gh-pages分支: git reset --hard origin/gh-pages

I think that you are missunderstanding commit and push . 我认为您是误会的commitpush

A commit is like a pictures you are shooting with a camera. commit就像您使用相机拍摄的图片。 (you specifie what elements you want to add to this pictures with add ). (你specifie要添加到这个图片什么元素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. push用于将您的相册发送到存储库。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM