Home > Back-end >  Undo Git changes after commiting and pushing
Undo Git changes after commiting and pushing

Time:10-18

I replaced 3 files in a directory in the master branch. For instance, I replaced a.txt, b.txt and c.txt with same name but new content. Then I added in the stagging area, commited and pushed to the central repo.

Whole operation was performed by Root user, later I realized that I had to perform the operation from puppet user.

The steps I took were reverting back to the second last commit. After reverting, I saw the replaced files were still intact with new content in the directory. Furthermore, the revert operation in "git status" was also marked as root user too.

How can I undo the changes locally and remotely and then perform with puppet user.

CodePudding user response:

You want to chown recursively using the puppet user so all files are owned properly. Then you can commit those changes and push. Make sure you're doing this under the puppet user.

CodePudding user response:

Let's say the hash of the commit you want to rollback to is 9650a10. Let's roll back the local changes and get back to this commit. To do this, you can use the following command:

git reset --hard 9650a10

After that, you can make a new commit. Then, to push changes with a "correct" commit to a remote repository, you can use the following command:

git push -f
  •  Tags:  
  • git
  • Related