关于git:如何在我推送代码时回滚到较旧的提交?

How to rollback to a older commit as I have pushed a code?

我在两个不同的分支AB上工作,我有一个prod分支MASTER,我创建了一个新的分支C,结合AB

我不小心把C推到MASTER上,现在我不知道该怎么做才能回到prod状态,因为有太多的承诺。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
commit 92e15c92d543e436bd5804ab6c9
Author: user_A
Date:   Thu Sep 22 15:51:47 2016 +0530

    fixing user report

commit dfd1f4e0d56f50d263d6e
Merge: 1a6bc83 f9b0a35
Author: user_A
Date:   Thu Sep 22 15:47:01 2016 +0530

    Merge branch 'MASTER' of git_repo_branch into B

commit 1a6bc83c55cf1b3d7f88d
Author: user_A
Date:   Thu Sep 22 15:46:46 2016 +0530

    fixing user report

commit dd11a998f380c70b579d2a0
Author: user_A
Date:   Thu Sep 22 13:09:29 2016 +0530

    fixing rake task

commit c194f900e58f93b0a06ed
Author: user_A
Date:   Thu Sep 22 13:08:40 2016 +0530

    fixing rake task

commit f9b0a35430d29826622d95
Author: user_B
Date:   Thu Sep 22 11:36:50 2016 +0530

    jobs save as draft fix

commit 3a1b233b365a96886e2d73
Merge: 2eac96c c4f61b1
Author: user_A
Date:   Thu Sep 22 11:35:20 2016 +0530

    Merge branch 'A' into B

commit dfd1f4e0d56f50d263d6eb5
Merge: 1a6bc83 f9b0a35
Author: user_A
Date:   Thu Sep 22 15:47:01 2016 +0530

    Merge branch 'MASTER' of git_repo_branch into B

commit 1a6bc83c55cf1b3d7f88da697411d5c5acb5b9c4
Author: user_A
Date:   Thu Sep 22 15:46:46 2016 +0530

    fixing user report

commit dd11a998f380c70b579d2a0b
Author: user_A
Date:   Thu Sep 22 13:09:29 2016 +0530

    fixing rake task

commit c194f900e58f93b0a06eddf8
Author: user_A
Date:   Thu Sep 22 13:08:40 2016 +0530

    fixing rake task

commit f9b0a35430d29826622d9
Author: user_B
Date:   Thu Sep 22 11:36:50 2016 +0530

    jobs save as draft fix

commit 3a1b233b365a96886e2d7334
Merge: 2eac96c c4f61b1
Author: user_A
Date:   Thu Sep 22 11:35:20 2016 +0530

    Merge branch 'A' into B

commit c4f61b151c28ce36b0c7987276df90ddc91c84fc
Merge: 0f18c62 fb70961
Author: user_A
Date:   Thu Sep 22 11:35:04 2016 +0530

commit f9b0a35430d29826622d950b9e149c05cf937644
Author: user_B
Date:   Thu Sep 22 11:36:50 2016 +0530

    jobs save as draft fix

commit 3a1b233b365a96886e2d73
Merge: 2eac96c c4f61b1
Author: user_A
Date:   Thu Sep 22 11:35:20 2016 +0530

Author: user_A
Date:   Thu Sep 22 13:08:40 2016 +0530

    fixing rake task

commit f9b0a35430d29826622d950b9
Author: user_B
Date:   Thu Sep 22 11:36:50 2016 +0530

    jobs save as draft fix

commit 3a1b233b365a96886e2d733403fa66e8dd4992fc
Merge: 2eac96c c4f61b1
Author: user_A
Date:   Thu Sep 22 11:35:20 2016 +0530

    Merge branch 'A' into B

commit c4f61b151c28ce36b0c79872
Merge: 0f18c62 fb70961
Author: user_A
Date:   Thu Sep 22 11:35:04 2016 +0530

    Merge branch 'MASTER' of git_repo_branch into A

commit 0f18c62cbae31b5f6a76d
Author: user_A
Date:   Thu Sep 22 11:34:06 2016 +0530

    changing name to slug

commit 56fbcd2e544d97aef2bb
Author: user_A
Date:   Thu Sep 22 11:28:38 2016 +0530

    changing name to slug

commit 2eac96cc7c56aa1f3bda29b9257e045c3b923dfe
Merge: 0caa9d1 f794d6e
Author: user_A
Date:   Wed Sep 21 17:08:37 2016 +0530

    added A_to_B

commit 0caa9d1076ee83d53b0586f2e7cd79f16320ac0e
Merge: 5df1d6d fb70961
Author: user_A
Date:   Wed Sep 21 15:49:40 2016 +0530

    removing conflict

commit f794d6ee277f0ba5964dc534c05cfe234761e569
Author: user_A
Date:   Wed Sep 21 15:41:21 2016 +0530

    fixing users name

commit cc97e8749cccdfee47bb67bbe6470639afbd1d28
Author: user_A
Date:   Wed Sep 21 15:15:53 2016 +0530

    raising 404 if user not found

commit fb709619d0a9f39c6b2a2c7b5a08c47835970c0f
Author: user_B
Date:   Wed Sep 21 12:44:32 2016 +0530

    usercount yopwise report

commit a332dfe71fd7de74eadcce43337699bb4205e29d
Author: user_A
Date:   Tue Sep 20 17:29:35 2016 +0530

    code error fix

commit 323fa5ed6b2002a664adcfc1ae6b295198258fe2
Author: user_A
Date:   Tue Sep 20 17:22:50 2016 +0530

    limiting

commit ea94a85e1ad259162d4a883cda08635697012602
Author: user_A
Date:   Tue Sep 20 17:15:17 2016 +0530


您可以回滚到以前的提交,查看git log以了解更多详细信息,然后强制您对主分支机构的承诺:

1
git push origin +<shaofcommit>:master

+将强制提交,或者您也可以使用-f选项。