简体   繁体   中英

Restoring a Git Repository to a particular date

I would like to restore my local git repository to a particular date. By restoring, I would like to keep all the commits and history which occurred till that date and time.

I am all okay to loose changes and commits which were performed after that date and time. (Assuming Jan 1st, 2014 11:30 AM)

Is this possible ?

git reset --hard 'master@{2014-01-01 11:30:00}'

那将在那之前将主分支重置为最接近的提交。

To update all of your refs, you can use git for-each-ref which can generate the command to run on each ref, then pipe the output of that to your shell.

git for-each-ref --shell \
    --format="git update-ref %(refname) %(refname)@{2014-01-01 11:30:00}" | sh

Any time you run a command like this, make sure you have a backup so you can restore the repository if something goes wrong. Also, try it once without the pipe to sh to see the commands that will be executed and make sure they look reasonable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM