M
M
mcrack2021-11-02 21:54:07
git
mcrack, 2021-11-02 21:54:07

How to remove a file from the committee in GIT if it has already been pushed?

I recently got a job as a developer, before that I did not work in a team and now I wanted to find out.

I made a commit, then pushed to a new branch, but it turned out that I had an extra file in it - package-lock.json. I would like to get rid of it, re-commit and push, how to do it?

Do I need to delete the old commit or delete it in some other way?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yerlan Ibraev, 2021-11-02
@mad_nazgul

Google to the rescue:
https://git-scm.com/book/ru/v2/%D0%9E%D1%81%D0%BD%...

M
Maxim, 2021-11-02
@Tomio

If you want to directly change your pushed commit, then:
1 - switch to your branch.
2 - make edits (delete your file)
3 - execute

git commit --amend -m "Новое сообщение, которое затрет старое сообщение предыдущего коммита."

4 - do
git push --force
But it's better to make an additional commit, in which you delete the unnecessary file. There is nothing bad in this.

D
Dmitry, 2021-12-13
@dlnsk

If package-lock.json is a new file, then your command is doing something wrong... SagePtr has already explained above why this file should be in the repository.
If this file has changed for you, then YOU are doing something wrong ... Most likely you used the npm update command instead of npm install. The latter installs not new versions of packages, but those specified in package-lock.json. This is necessary so that all team members use the same package versions, otherwise expect surprises.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question