[英]changing the files in my git commit after performing a Git Push Command
so we make use of GitLab and so I had to send out a mergereq request.所以我们使用了 GitLab,所以我不得不发出一个 mergeeq 请求。 It was during the mergereq I realised that I had done a git commit of additional files " temporary and unrequired ";在合并期间,我意识到我已经对“临时和不需要的”附加文件进行了 git 提交; Is there a way of undoing this ?有没有办法撤销这个? I have tried我试过了
git commit --amend git commit --amend
But this changes only the commit message whereas I need to remove the unnecessary files as well.但这只会更改提交消息,而我还需要删除不必要的文件。
Is this possible?这可能吗?
No, git commit --amend
does allow you to add new modifications to the last commit.不, git commit --amend
确实允许您向最后一次提交添加新的修改。 The case in which it only updates the commit message is when you use the -m
parameter.它只更新提交消息的情况是当您使用-m
参数时。
But rather than trying to rm
unwanted files from the index, I'd suggest doing the following from your local branch* :但是,与其尝试从索引中rm
不需要的文件,我建议您从本地分支* 执行以下操作:
# undo last commit while keeping changes in the working tree
git reset HEAD^
# redo the adding part without the unwanted files
git add file1 file2 file3
# commit and push
git commit -m "message"
git push --force origin HEAD
Now just refresh your PR page, it will update itself, replacing the faulty commit with the new one.现在只需刷新您的 PR 页面,它就会自行更新,用新的提交替换错误的提交。
(* assuming this is your feature branch, on which you can force-push without disrupting someone else's work. Correct me if I'm wrong here) (* 假设这是您的功能分支,您可以在该分支上强制推送而不会中断其他人的工作。如果我在这里错了,请纠正我)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.