version control - Comment défaire les plus récents commits locaux de Git

Mots clés : gitversion-controlgit-commitundogit

meilleur 5 Réponses version control - Comment défaire les plus récents commits locaux de Git

vote vote

93

$ git commit -m "Something terribly misguided" # (0: Your Accident) $ git reset HEAD~                              # (1) [ edit files as necessary ]                    # (2) $ git add .                                    # (3) $ git commit -c ORIG_HEAD                      # (4) 
vote vote

81

   (F) A-B-C     ↑   master 
git reset --hard HEAD~1 
 (F) A-B   ↑ master 
   (F) A-B-C     ↑   master 
git reset HEAD~1 
   (F) A-B-C   ↑ master 
git reset --soft HEAD~1 
git checkout -b someNewBranchName shaYouDestroyed 
vote vote

72

git log     commit 101: bad commit    # Latest commit. This would be called 'HEAD'.     commit 100: good commit   # Second to last commit. This is the one we want. 
git reset --soft HEAD^     # Use --soft if you want to keep your changes git reset --hard HEAD^     # Use --hard if you don't care about keeping the changes you made 
git revert HEAD 
git commit -m 'restoring the file I removed by accident' git log     commit 102: restoring the file I removed by accident     commit 101: removing a file we don't need     commit 100: adding a file that we need 
vote vote

67

git rm classdir git add sourcedir 
git commit --amend 
vote vote

53

git rm yourfiles/*.class git commit -a -m "deleted all class files in folder 'yourfiles'" 
git reset --hard HEAD~1 

Questions similaires