-1

I did:

git clone <some repo>
git checkout development
git checkout -b my-feature

updated somefolder/somefile.sh and other files and did multiple commits, pushed the changes and did rebase:

git commit -a -m "somefile update"
git push origin my-feature
git rebase origin/development -i

and created a merge request in GitLab, but some reviewer requested to rollback all changes I made in somefoler/somefile.sh (in my-feature branch)

What is the right command for that?

AD7six
  • 63,116
  • 12
  • 91
  • 123
Alexey Starinsky
  • 3,699
  • 3
  • 21
  • 57
  • What do you want to roll back? Did you change multiple files but want to undo only changes to somefolder/somefile.sh? git reset development # This will discard all changes on your branch git checkout development file.sh # This will bring back the file.sh from the development branch git revert # This will revert one commit after a git rebase develompent -i you will need to do a git push -f – drahnoel Feb 13 '23 at 11:50
  • @drahnoel yes, changed multiple files and pushed them, but need to undo only changes to `somefolder/somefile.sh` – Alexey Starinsky Feb 13 '23 at 12:17
  • So then AD7six answered your question. – drahnoel Feb 20 '23 at 13:06

1 Answers1

1

There are multiple ways to do this but the simplest is:

$ git fetch
$ git checkout origin/develop somefolder/somefile.sh
$ git commit -m "reset to develop" somefolder/somefile.sh

That creates a new commit undoing the effects of any previous commits in the branch to that one file.


An alternative approach is to rebase the change out, the ease of doing that depends on how the commits are composed. Please see "Cleaning commit history" in this answer for a description of how to do that.

AD7six
  • 63,116
  • 12
  • 91
  • 123