EN
Git - rollback commit (using git reset --hard)
4 points
In this quick article we would like to show how to rollback pushed commmit with git with git reset --hard
command.
Quick solution:
xxxxxxxxxx
1
git reset --hard MY_COMMIT_HASH
2
git push --force
Note:
--hard
parameter is optional.
In this section you can see full example how to rollback commit with git reset --hard
.
Note: using this approach, it is good to notify other people in team about rolling back to previous version.
Simple steps:
- find commit hash you want to recover
xxxxxxxxxx
1$ git log --graph
2
3* commit 205c851ba0507d04e5e3f00ee48fb2ac01f4fd80 (HEAD -> 2020_03_15_ui, origin/2020_03_15_ui)
4| Author: john <john@mail.com>
5| Date: Thu Jul 16 18:50:28 2020 +0200
6|
7| UI: updated REST API for new backend
8|
9* commit 2ec125f7eba3238bcfe2e22b9c44b7c6e22e7052
10| Author: john <john@mail.com>
11| Date: Tue Jul 14 19:43:49 2020 +0200
12|
13| UI: common footer component for all service
14|
15* commit c9b6a24575c9cdf1f43da3d45cde00148e7c75a7
16| Author: john <john@mail.com>
17| Date: Tue Jul 14 17:22:19 2020 +0200
18|
19| UI: removed unused code
20|
21* commit 465755bead3d3afe386e702540644427c250bcb0
22| Author: john <john@mail.com>
23| Date: Tue Jul 14 16:29:04 2020 +0200
24|
25| UI: new routing rules
26|
- reset changed to proper commit
(e.g. we want to recover source code to465755bead3d3afe386e702540644427c250bcb0
)xxxxxxxxxx
1$ git reset --hard 465755bead3d3afe386e702540644427c250bcb0
2
3HEAD is now at 465755be UI: new routing rules
4
5$ git log --graph
6
7* commit 465755bead3d3afe386e702540644427c250bcb0 (HEAD -> 2020_03_15_ui, origin/2020_03_15_ui)
8| Author: john <john@mail.com>
9| Date: Tue Jul 14 16:29:04 2020 +0200
10|
11| UI: new routing rules
12|
13* commit 401d25b3a48c96c08a453def29f9e1df5ec3f25a
14| Author: john <john@mail.com>
15| Date: Tue Jul 14 14:56:42 2020 +0200
16|
17| UI: improved left page menu - expand/collapse for submenus
18|
19* commit b29eca1e52bc0bd2eb7d211158d060338605a9ca
20|\ Merge: c189dc14 f3e85ee7
21| | Author: john <john@mail.com>
22| | Date: Tue Jul 14 02:48:02 2020 +0200
23| |
24| | Merge branch '2020_03_15_ui' of https://bitbucket.org/great-team/shop into 2020_03_15_ui
25| |
26| * commit f3e85ee7049dc8d89a7a309d6fe2ea9d3c64a63d
27| | Author: john <john@mail.com>
28| | Date: Tue Jul 14 00:31:57 2020 +0200
29| |
30| | UI: fix for image orientation on mobile devices
31| |
- pushing changes with
--force
Note: notify other team members that you push your changes to remote repository.
xxxxxxxxxx
1$ git push --force
2
3Total 0 (delta 0), reused 0 (delta 0)
4remote:
5remote: Create pull request for 2020_03_15_ui:
6remote: https://bitbucket.org/great-team/shop/pull-requests/new?source=2020_03_15_ui&t=1
7remote:
8To https://bitbucket.org/great-team/shop.git
9+ 205c851b...465755be 2020_03_15_ui -> 2020_03_15_ui (forced update)