r - 如何在 R studio 中恢复到以前的 git?

标签 r git github rstudio

我知道很多帖子都解决了类似的问题,但我还是想不出如何解决这个问题。

所以,我已经将我的本地目录与这个 git 仓库同步

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

但是,我的本地目录并没有像我期望的那样显示 check out 提交中存在的文件

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

最佳答案

如果您只想恢复这些文件,并且要在 master 分支上这样做,那么您应该:

  • 检查主分支
  • 只检查上次提交的那些文件
  • 暂存更改(恢复的文件)
  • 进行新的提交

这看起来像下面这样:

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

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

关于r - 如何在 R studio 中恢复到以前的 git?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38465025/

相关文章:

r - 使用 rlang 选择整个数据框而不仅仅是一列

r - 一组内的多个箱线图

r - ggplot2:更改geom_segment 甘特图中段的颜色?

git - 如何执行 git diff 排除某些文件类型?

git - 推送分支到 Git

r - R 中的 fminsearch 比 Matlab 中的差

git - 在推送通知邮件中添加 git diff

azure - 继续部署无法与 github 私有(private)存储库正常工作

node.js - 在 github 页面上托管我的 MEAN 堆栈 Web 应用程序

ios - 一个开源项目如何在不发布一些(私有(private))参数的情况下发布?