推到Git,一切都消失了



所以我是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 meetuma,然后从github克隆了我的项目,所以问题就解决了。不过我还是想知道发生了什么。

在我看来,您在粘贴问题之前创建了一个名为"work"的分支。然后,您向master分支提交了一些更改(下面的"newcommit")并推送了这些更改。然后,您签出了在新提交之前从中分支的"work"分支。这意味着它不会包含新的提交。如果你再次结账,你会再次看到你的更改。

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

所以,如果您签出"工作",那么newcommit就不会出现在该分支上。或者可能在"work"分支上从来没有任何新的提交,在这种情况下,"work"仍然指向basecommit:

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

所以,如果你签出"工作",你就会回到新委员会存在之前。请记住,git中的分支只是指向在添加提交时自动移动的提交的指针(标记是不自动移动的指针)。

最新更新