如何在 R studio 中恢复到之前的 git?
How do I revert to a previous git in R studio?
我知道很多帖子都解决了类似的问题,但我还是想不出如何解决这个问题。
因此,我已将我的本地目录与此 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
但是,我的本地目录没有像我期望的那样显示检出提交中存在的文件
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
.
我知道很多帖子都解决了类似的问题,但我还是想不出如何解决这个问题。
因此,我已将我的本地目录与此 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
但是,我的本地目录没有像我期望的那样显示检出提交中存在的文件
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
.