P
P
prolina2019-08-21 12:00:08
git
prolina, 2019-08-21 12:00:08

Rollback git changes?

Hello everyone) Such a question: I committed unnecessary changes in one file (but the commit contained changes to several files), you need to return to the state as it was before the commit in this file and add only one line to the commit (now a lot of unnecessary things have been added + one line of code needed). After this commit, many commits were made and everything was pushed. Now we need to somehow rewrite this commit.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alekseyHunter, 2019-08-21
@alekseyHunter

If you need to remove a commit and it has not been published:
If it has been published, make a commit to undo the commit. After we do push.
git revert commit-sha1

A
Anton Shvets, 2019-08-21
@Xuxicheta

You need to carefully return to the old state through git reset --hard хэшкоммита
Then manually repeat all the commits that were after (and they will be under your name)
And then push all this into the remote turnip through git push --force
This will change the history. Of course, if you have the appropriate rights.
But if it's possible, stick to the usual revertone (it adds a new commit that rolls back your changes), or just commit with manual changes. Git is designed this way, it doesn't welcome history changes.
Everyone has shoals, often an attempt to hide them is more expensive than an honest confession.

T
tsarevfs, 2019-08-21
@tsarevfs

If the changes occurred in a repository that only you used or these are changes in your branch, then you can change the history.
https://habr.com/en/post/201922/
git rebase -i is your choice for complex changes
After that, to overwrite the remote copy of the branch, you need to push --force
Important : History changes are almost irreversible. Reverting erroneous changes will be difficult or impossible. Copy the entire folder with the repository in case of problems, if you are not sure what to do.
Important : If several people work with a branch, or even you from 2 different machines, for example, at home and at work, then if the history changes, it will be difficult to save changes from another machine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question