-1

I added file and push it. I realize later that the file2 should not be added. How could I do please?

Code

git add f1.txt
git add f2.txt
git commit -m 'add f1'
git push origin feature_1

I did

git reset --soft HEAD~1
git reset HEAD path/to/f2
git commit -m 'add f1'  

and im still having the file in my Merge Request on GIT.

Thân LƯƠNG Đình
  • 3,082
  • 2
  • 11
  • 21
biwia
  • 407
  • 1
  • 4
  • 10

2 Answers2

0

If you are sure nobody has seen your push, you can do:

  1. git reset HEAD~1
  2. git add file1.txt
  3. git commit -m 'add f1'
  4. git push -f

But you need to be very carefull when force-pushing. Make sure nobodys work based on the old commit!

0

In case you want to change the latest commit, you could try following solution.

Remove file that you want to delete.

git rm f2.txt

The command removes the file from the repo but also deletes it from the local file system. To remove the file from the repo and not delete it from the local file system, you could use:

git rm --cached f2.txt

After, you use:

git commit --amend

Finally, you use:

git push --force
Thân LƯƠNG Đình
  • 3,082
  • 2
  • 11
  • 21