0

Here's the full situation:

  1. The commit below is my last commit ever made.

    commit 2d1efd9c58b44542f81ccba6e33eb698665e7fec
    Author: Jeramae Bohol <mr.jeramaebohol@gmail.com>
    Date:   Thu May 12 07:00:14 2016 +0000
    
    Add account activations
    
  2. Then after that commit, I made a big mistake deleting the wrong migration file but the good thing is I haven't commit this yet.

My question is, how can I checkout to my last commit and ignore/delete this one that I made a mistake?

Jeramae Bohol
  • 191
  • 1
  • 1
  • 6

4 Answers4

0

try this

since you have deleted file after the commit

git status

now copy your deleted filepath

run this command

git checkout deleted_filepath
Pravesh Khatri
  • 2,124
  • 16
  • 22
0

git reset to your last commit & make sure it will delete all your uncommitted files/codes:

git reset --hard 2d1efd9c58b44542f81ccba6e33eb698665e7fec
dp7
  • 6,651
  • 1
  • 18
  • 37
  • This is the message after I ran your code: HEAD is now at 2d1efd9 Add account activations. Then when I ran git status, the files that I want to be deleted are still present but just untracked. How can I completely discard all the things I made after my last commit? – Jeramae Bohol May 12 '16 at 07:39
  • @JeramaeBohol 'git commit' would discard untracked files. – dp7 May 12 '16 at 07:44
  • but there's nothing to commit because the files I want to be deleted are all untracked. – Jeramae Bohol May 12 '16 at 07:46
  • @JeramaeBohol http://stackoverflow.com/questions/61212/how-do-i-remove-local-untracked-files-from-my-current-git-branch – dp7 May 12 '16 at 07:51
  • I figured it out. Thanks – Jeramae Bohol May 12 '16 at 08:04
0

Add that file path to your .gitignore file and then commit your .gitignore file

 /log/*
!/log/.keep
/tmp
/path_to_your_migration_file
kajal ojha
  • 1,248
  • 8
  • 20
0

You can simply write command

git checkout file_path

It will add your deleted file to your directory

Amol Udage
  • 2,917
  • 19
  • 27