如何在R studio中恢复之前的git?

时间:2016-07-19 17:34:43

标签: r git github rstudio

我知道在一些帖子中已经解决了类似的问题,但无论如何我都无法弄清楚如何解决这个问题。

所以,我已将本地目录与此git repo同步

Dario (master *) replicationKumar $ git remote -v
origin  git@github.com:DarioBoh/replicationKumar.git (fetch)
origin  git@github.com:DarioBoh/replicationKumar.git (push)

我成功推送了一些提交,所以我非常有信心我已经正确地同步了一切。 另外,我跑了

Dario (master *) replicationKumar $ git pull origin master
From github.com:DarioBoh/replicationKumar
 * branch            master     -> FETCH_HEAD
Already up-to-date.

这表明我应该在github上制作一份我的副本。 自上次提交以来,我删除了一些文件,现在我想从此提交中从远程目录中恢复所有文件

Dario (master *) replicationKumar $ git log
commit 91a3dfdb30084654a7a5517250d2a70dfddb931b
Author: DarioBoh <bonarettidario@gmail.com>
Date:   Tue Jul 19 10:00:12 2016 -0500

    REFACTOR linechart moved from server to chart.R

实际上,本地目录目前看起来像这样

Dario (master *) replicationKumar $ ls -a
.           .RData          .Rproj.user     .gitignore
..          .Rhistory       .git            replicationKumar.Rproj

我以为checkout会完成这项工作而我做了

Dario (master *) replicationKumar $ git checkout 91a3dfdb30084654a7a5517250d2a70dfddb931b
D   charts.R
D   datasets.R
D   server.R
D   sidebarMenu.R
D   ui.R
D   ui1.R
D   ui2.R
Note: checking out '91a3dfdb30084654a7a5517250d2a70dfddb931b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 91a3dfd... REFACTOR linechart moved from server to chart.R

但是,我的本地目录不会像我期望的那样显示签出提交中存在的文件

Dario ((91a3dfd...) *) replicationKumar $ ls -a
.           .Rhistory       .gitignore
..          .Rproj.user     FETCH_HEAD
.RData          .git            replicationKumar.Rproj

1 个答案:

答案 0 :(得分:3)

如果您希望仅还原这些文件,并在主分支上执行此操作,那么您应该:

  • 查看主分支
  • 仅查看上一次提交
  • 中的文件
  • 暂存更改(已还原的文件)
  • 进行新的提交

这将类似于以下内容:

git checkout master
git checkout [commit hash] [path/to/file.txt]
...
git add .
git status (does everything look right?)
git commit

这将向master添加一个新提交,它将文件从指定的旧提交恢复为其状态。之后您可能想要运行另一个git push