推到Git,一切都消失了?

时间:2012-03-15 02:03:08

标签: git github

所以我是Ruby on Rails的新手。我提交了所有内容并将其推送到git,然后我的项目又恢复为旧版本。我最近的版本安全地存储在git上,但现在我的计算机上的所有原始文件都已消失,并被旧版本的文件取代。发生了什么事?

编辑:更多详情:

git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .DS_Store
#   modified:   app/.DS_Store
#   modified:   app/assets/stylesheets/static_pages.css.scss
#   modified:   app/views/static_pages/home.html.erb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   app/assets/.DS_Store
#   app/assets/images/.DS_Store
#   public/chat.png
#   public/groups.png
#   public/join-free.png
#   public/login-button.png
#   public/meetups.png
#   public/people.png
#   public/posts.png
#   public/profile.png
#   public/stream.png
#   public/streambaby.png
#   public/streamblue.png
#   public/streamlime.png
no changes added to commit (use "git add" and/or "git commit -a")
Lasers-MacBook-Pro:meetumea lasernite$ git add .
Lasers-MacBook-Pro:meetumea lasernite$ git commit -m "home page basic"
[master 49921d4] home page basic
 Committer: Laser Nite <lasernite@Lasers-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 18 files changed, 144 insertions(+), 9 deletions(-)
 create mode 100644 app/assets/.DS_Store
 create mode 100644 app/assets/images/.DS_Store
 rewrite app/assets/stylesheets/static_pages.css.scss (100%)
 rewrite app/views/static_pages/home.html.erb (100%)
 create mode 100644 public/chat.png
 create mode 100644 public/groups.png
 create mode 100644 public/join-free.png
 create mode 100644 public/login-button.png
 create mode 100644 public/meetups.png
 create mode 100644 public/people.png
 create mode 100644 public/posts.png
 create mode 100644 public/profile.png
 create mode 100644 public/stream.png
 create mode 100644 public/streambaby.png
 create mode 100644 public/streamblue.png
 create mode 100644 public/streamlime.png
Lasers-MacBook-Pro:meetumea lasernite$ git branch
* master
  work
Lasers-MacBook-Pro:meetumea lasernite$ git push
Counting objects: 39, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 60.94 KiB, done.
Total 27 (delta 11), reused 0 (delta 0)
To git@github.com:lasernite/meetumea.git
   a78c8f0..49921d4  master -> master
Lasers-MacBook-Pro:meetumea lasernite$ git status
# On branch master
nothing to commit (working directory clean)
Lasers-MacBook-Pro:meetumea lasernite$ git co work
Switched to branch 'work'
Lasers-MacBook-Pro:meetumea lasernite$ git status
# On branch work
nothing to commit (working directory clean)

然后我注意到我的所有文件都是旧版本,所有我的新图像都从公共文件夹中消失了。我刚刚运行了rm -rf meetumea,然后从github克隆了我的项目,所以问题就解决了。不过,我仍然想知道发生了什么。

1 个答案:

答案 0 :(得分:4)

在我看来,就像你在问题中粘贴之前创建了一个名为“work”的分支。然后,您对主分支(下面的'newcommit')进行了一些更改并推送了它。然后,您检查了在新提交之前分支的“工作”分支。这意味着它不会包含新的提交。如果你再次结帐主人,你会再次看到你的变化。

newcommit (master)
  |
  |
  |                  othercommit (work)
  |                    /
basecommit------------'

因此,如果您结帐'work',那么newcommit将不会在该分支上。或者可能在“工作”分支上没有任何新的提交,在这种情况下,“工作”仍然指向basecommit:

newcommit (master)
  |
  |
  |
  |
basecommit (work)

因此,如果你结账'工作',你就会在新的委员会存在之前回来。请记住,git中的分支只是指向提交时的指针,这些提交会在您添加提交时自动移动(并且标记是不会自动移动的指针)。