i*****h 发帖数: 1534 | 1 RT, 对git实在不熟悉,请问谁知道能否删除已经merge到master上的文件? 非常感谢
之前request没有merge前,我一直用的git reset --soft HEAD~num ,来删commit
现在已经merge到master上了应该怎么恢复? |
i*****h 发帖数: 1534 | |
w*****x 发帖数: 11 | 3 git reflog
然后看看哪一步
应该是git rest --soft HEAD@{n} n是你的要回到的地方 |
w*****x 发帖数: 11 | |
i*****h 发帖数: 1534 | 5 非常感谢!
之前request没有merge前,我一直用的git reset --soft HEAD~num ,来删commit
现在已经merge到master上了应该怎么恢复? |
d*******s 发帖数: 65 | |
p****n 发帖数: 17 | |
i*****h 发帖数: 1534 | |
g*****g 发帖数: 34805 | |
i*****h 发帖数: 1534 | 10 git revert HEAD~1?
【在 g*****g 的大作中提到】 : 如果是最上面,可以git revert。
|
|
|
t*****d 发帖数: 525 | 11 关键看你有没有 push to remote.
yes: you need git revert
no: just git rebase -i
【在 i*****h 的大作中提到】 : RT, 对git实在不熟悉,请问谁知道能否删除已经merge到master上的文件? 非常感谢 : 之前request没有merge前,我一直用的git reset --soft HEAD~num ,来删commit : 现在已经merge到master上了应该怎么恢复?
|
i*****h 发帖数: 1534 | 12 已经push to remote了,看网上用git rebase -i 能删除,但是我自己试了一下结果不
一样
试了一下git rebase -i commit_id
然后看了下纪录,按视频上来看应该出现两条commits,但是现在出现很多
【在 t*****d 的大作中提到】 : 关键看你有没有 push to remote. : yes: you need git revert : no: just git rebase -i
|
d*******s 发帖数: 65 | 13 我一般这么做,不排除有大牛有更厉害的做法。
如果你要删除的commit改了文件A,你的patch已经merge到remote,而且在你之上文件A
没有新的merged commit。那么你可以先用git log 找到你的commit id。然后
git revert 。然后upload这个revert commit。等这个merge了就好了。
【在 i*****h 的大作中提到】 : git revert HEAD~1?
|
i*****h 发帖数: 1534 | 14 用了git rebase -i commit_id
出现的所有纪录是我merge前的,我想删的那个commit没有 |
d*******s 发帖数: 65 | 15 git rebase --continue回到tip?
【在 i*****h 的大作中提到】 : 用了git rebase -i commit_id : 出现的所有纪录是我merge前的,我想删的那个commit没有
|
i*****h 发帖数: 1534 | 16 我的merge是 #6,用git rebase,就只能显示出#5或之前的东西,删不了我要删的
【在 d*******s 的大作中提到】 : git rebase --continue回到tip?
|
w*****x 发帖数: 11 | |
w**z 发帖数: 8232 | 18 you should use git revert, it will revert your commit by adding a new commit
. you won't be able to erase your commit.
【在 i*****h 的大作中提到】 : 我的merge是 #6,用git rebase,就只能显示出#5或之前的东西,删不了我要删的
|
b**********5 发帖数: 7881 | 19 你已经push 到remote了, 还rebase什么? revert
【在 i*****h 的大作中提到】 : 已经push to remote了,看网上用git rebase -i 能删除,但是我自己试了一下结果不 : 一样 : 试了一下git rebase -i commit_id : 然后看了下纪录,按视频上来看应该出现两条commits,但是现在出现很多
|
i*****h 发帖数: 1534 | 20 能给个具体的command吗?多谢
【在 b**********5 的大作中提到】 : 你已经push 到remote了, 还rebase什么? revert
|
|
|
w**z 发帖数: 8232 | 21 你不会读文档吗?都说revert 了,还不会?
【在 i*****h 的大作中提到】 : 能给个具体的command吗?多谢
|
i*****h 发帖数: 1534 | 22 那个request里有5个commit,其中一个是错的。之前用git reset --hard HEAD~1 在
local branch里把那个错的删了,然后git push -f, master上还有。
能问下现在该怎么操作?比如我要删除merge #6的一个commit, 去master上 git
revert commit_id?
commit
【在 w**z 的大作中提到】 : you should use git revert, it will revert your commit by adding a new commit : . you won't be able to erase your commit.
|
i*****h 发帖数: 1534 | 23 读了,试过了不一样,之前看视频也是这样说,但是弄出来不一样
【在 w**z 的大作中提到】 : 你不会读文档吗?都说revert 了,还不会?
|
d*******s 发帖数: 65 | 24 1. git rebase --abort // discard whatever you have done in rebase
2. git update remote
3. git rebase origin/master // assume you are on master branch
4. git log
5. git revert
【在 i*****h 的大作中提到】 : 能给个具体的command吗?多谢
|
g*****g 发帖数: 34805 | 25 应该是soft reset吧,然后可以push -f。不过master上不推荐这么做。还是revert安
全。
git
【在 i*****h 的大作中提到】 : 那个request里有5个commit,其中一个是错的。之前用git reset --hard HEAD~1 在 : local branch里把那个错的删了,然后git push -f, master上还有。 : 能问下现在该怎么操作?比如我要删除merge #6的一个commit, 去master上 git : revert commit_id? : : commit
|
t*****d 发帖数: 525 | 26 I think you screwed your local client, 重新开个 client 来 revert. 吧
牛肉姐都会,你好好学吧,学完记得奔一个。
git
【在 i*****h 的大作中提到】 : 那个request里有5个commit,其中一个是错的。之前用git reset --hard HEAD~1 在 : local branch里把那个错的删了,然后git push -f, master上还有。 : 能问下现在该怎么操作?比如我要删除merge #6的一个commit, 去master上 git : revert commit_id? : : commit
|
b**********5 发帖数: 7881 | 27 看了我头晕。 我建议如果错误的东西不是太多的话, 还不如果重新checkout master
到一个new branch, modify, 然后push。 就当一个新的modification
git
【在 i*****h 的大作中提到】 : 那个request里有5个commit,其中一个是错的。之前用git reset --hard HEAD~1 在 : local branch里把那个错的删了,然后git push -f, master上还有。 : 能问下现在该怎么操作?比如我要删除merge #6的一个commit, 去master上 git : revert commit_id? : : commit
|
d*******s 发帖数: 65 | 28 我一开始也这么想,但看标题似乎楼主想要删除一个文件
master
【在 b**********5 的大作中提到】 : 看了我头晕。 我建议如果错误的东西不是太多的话, 还不如果重新checkout master : 到一个new branch, modify, 然后push。 就当一个新的modification : : git
|
w**z 发帖数: 8232 | 29 git revert
git push
git rest 不要乱用。
git
【在 i*****h 的大作中提到】 : 那个request里有5个commit,其中一个是错的。之前用git reset --hard HEAD~1 在 : local branch里把那个错的删了,然后git push -f, master上还有。 : 能问下现在该怎么操作?比如我要删除merge #6的一个commit, 去master上 git : revert commit_id? : : commit
|
g*****g 发帖数: 34805 | 30 reset在feature branch上用用是没什么的,push到remote上的commit,可以soft
reset,然后force push就去掉了,历史也很干净。Master上就算了,一不小心master
就没了。我们都是设定不允许对master force push。
【在 w**z 的大作中提到】 : git revert : git push : git rest 不要乱用。 : : git
|
|
|
w**z 发帖数: 8232 | 31 我一般都是revert, 反正commit 多几个无所谓。git 本来就随便commit.
master
【在 g*****g 的大作中提到】 : reset在feature branch上用用是没什么的,push到remote上的commit,可以soft : reset,然后force push就去掉了,历史也很干净。Master上就算了,一不小心master : 就没了。我们都是设定不允许对master force push。
|
i*****h 发帖数: 1534 | 32 请教下,网上看到是这样说的:
git reset:用於做整段 commits 的還原
git rebase:假如想要抽掉某個 commit 又不想留下記錄
git revert:想要還原到某个commit 之後的狀態
我看一下好像都是能达到一样效果的,那一般情况下到底用什么比较好呢 |
z****e 发帖数: 54598 | 33
doesnt matter, but ppl prefer to use revert
it seems like a standard operation 4 all cvs(es)
【在 i*****h 的大作中提到】 : 请教下,网上看到是这样说的: : git reset:用於做整段 commits 的還原 : git rebase:假如想要抽掉某個 commit 又不想留下記錄 : git revert:想要還原到某个commit 之後的狀態 : 我看一下好像都是能达到一样效果的,那一般情况下到底用什么比较好呢
|
g*****g 发帖数: 34805 | 34 整个拿掉差别不大,你发现上个commit错了,但又想选择性保留的时候soft reset好用。
【在 w**z 的大作中提到】 : 我一般都是revert, 反正commit 多几个无所谓。git 本来就随便commit. : : master
|
g*****g 发帖数: 34805 | 35 public branch用revert,private用reset。reset灵活性更大一些,revert比较安全。
rebase 是在
private branch上sync public branch上的修改的时候用的。
【在 i*****h 的大作中提到】 : 请教下,网上看到是这样说的: : git reset:用於做整段 commits 的還原 : git rebase:假如想要抽掉某個 commit 又不想留下記錄 : git revert:想要還原到某个commit 之後的狀態 : 我看一下好像都是能达到一样效果的,那一般情况下到底用什么比较好呢
|
i*****h 发帖数: 1534 | 36 现在自己branch里的东西删了,但是git push -f到master被reject了,好像没法改,
是因为权限问题? |
i*****h 发帖数: 1534 | 37 明白了,多谢
【在 g*****g 的大作中提到】 : public branch用revert,private用reset。reset灵活性更大一些,revert比较安全。 : rebase 是在 : private branch上sync public branch上的修改的时候用的。
|
i*****h 发帖数: 1534 | 38 改merge conflict的时候影响到了人家的东西,有什么办法把master上的东西改掉吗?
就像回到merge #5,但是好像没法更新到master上 |
i*****h 发帖数: 1534 | |
i*****h 发帖数: 1534 | 40 问个题外话,一般用git是不是应该在修改东西前update local branch,这样可以减少
merge conflict,我看组里大家都是40+ commits behind master,这样是不是不太好
?
另外我看有人提到每个JIRA开一个新的branch,这种做法是标准吗?fix后merge完了,
然后删掉branch。这样是不是更好? |
|
|
b**********5 发帖数: 7881 | 41 我以前基本每个bug, 每个feature一个branch。。 用git的好处, 就是branch啊。
【在 i*****h 的大作中提到】 : 问个题外话,一般用git是不是应该在修改东西前update local branch,这样可以减少 : merge conflict,我看组里大家都是40+ commits behind master,这样是不是不太好 : ? : 另外我看有人提到每个JIRA开一个新的branch,这种做法是标准吗?fix后merge完了, : 然后删掉branch。这样是不是更好?
|
i*****h 发帖数: 1534 | 42 组里的人都不太懂git,都是perforce过来的,组里老大规定一个人只能开一个branch
(还是永久性的),反正跟着这个流程感觉干什么都很费劲,一堆commits behind
master,然后每个人都不停解决merge conflict
【在 b**********5 的大作中提到】 : 我以前基本每个bug, 每个feature一个branch。。 用git的好处, 就是branch啊。
|
i*****h 发帖数: 1534 | 43 又读了下git的文档,还挺有意思的,弄熟了用起来应该不错 |
N*****m 发帖数: 42603 | 44 pull都应该rebase
【在 i*****h 的大作中提到】 : 问个题外话,一般用git是不是应该在修改东西前update local branch,这样可以减少 : merge conflict,我看组里大家都是40+ commits behind master,这样是不是不太好 : ? : 另外我看有人提到每个JIRA开一个新的branch,这种做法是标准吗?fix后merge完了, : 然后删掉branch。这样是不是更好?
|
g*****g 发帖数: 34805 | 45 A few things that can help.
1. Keep feature branches short-lived. If your ticket is created as a small
deliverable, your branch just needs to match that.
1. Squash the commits before merging to master.
2. Rebase your feature branch frequently, small, incremental conflicts are
easier to resolve than big bang.
【在 i*****h 的大作中提到】 : 问个题外话,一般用git是不是应该在修改东西前update local branch,这样可以减少 : merge conflict,我看组里大家都是40+ commits behind master,这样是不是不太好 : ? : 另外我看有人提到每个JIRA开一个新的branch,这种做法是标准吗?fix后merge完了, : 然后删掉branch。这样是不是更好?
|
i*****h 发帖数: 1534 | 46 好的,谢谢指点
【在 N*****m 的大作中提到】 : pull都应该rebase
|
i*****h 发帖数: 1534 | 47 明白了,谢谢指点
【在 g*****g 的大作中提到】 : A few things that can help. : 1. Keep feature branches short-lived. If your ticket is created as a small : deliverable, your branch just needs to match that. : 1. Squash the commits before merging to master. : 2. Rebase your feature branch frequently, small, incremental conflicts are : easier to resolve than big bang.
|
w**z 发帖数: 8232 | 48 Make sure you understand
rebase vs merge
general rule is that
only rebase when you are on feature branch, never rebase when you are on
master
【在 i*****h 的大作中提到】 : 好的,谢谢指点
|
i*****h 发帖数: 1534 | 49 谢谢提醒,我重新看过文档了,现在基本了解了。
【在 w**z 的大作中提到】 : Make sure you understand : rebase vs merge : general rule is that : only rebase when you are on feature branch, never rebase when you are on : master
|