Git恢复到特定的提交

代码示例

14
0

如何在git中恢复到以前的提交

# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to.
8
0

git回滚到特定的提交

//Git Rollback to a specific commit via Mac terminal

//Navigate to project and open git log
cd projectname
git log --oneline

//Locate and checkout the desired commit ID
git checkout abc1234 . 

//(Type q to quit the git log)

//Stage All changes, commit with comment, and push to remote
git add -A
git commit -m "Revert commit: abc1234"
git push
2
0

签出之前的提交后,返回到最新的提交

git checkout <commit hash>	# go to previous commit
git revert <commit hash>  	# revert action of going to previous commit
1
0

返回一些提交git

git revert {commit_id}'
0
0

git pull from previous commit

git checkout -b old-state 0d1d7fc32
0
0

git命令更改为以前的comit

git revert --no-commit 0766c053..HEAD
git commit


If you really do want to have individual commits 
(instead of reverting everything with one big commit), 
then you can pass --no-edit instead of --no-commit, 
so that you don't have to edit a commit 
message for each reversion. – user456814

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................