Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在执行git Push命令后更改git commit中的文件_Git_Git Push - Fatal编程技术网

在执行git Push命令后更改git commit中的文件

在执行git Push命令后更改git commit中的文件,git,git-push,Git,Git Push,所以我们使用GitLab,所以我不得不发出一个mergereq请求。在mergereq期间,我意识到我已经完成了git提交的附加文件“临时且不需要”;有没有办法解决这个问题?我试过了 git提交--修改 但这只会更改提交消息,而我还需要删除不必要的文件 这可能吗?不,git commit--amend允许您向上次提交添加新的修改。当您使用-m参数时,它只更新提交消息 但是,与其尝试从索引中rm不需要的文件,我建议您在本地分支机构中执行以下操作*: # undo last commit while

所以我们使用GitLab,所以我不得不发出一个mergereq请求。在mergereq期间,我意识到我已经完成了git提交的附加文件“临时且不需要”;有没有办法解决这个问题?我试过了

git提交--修改

但这只会更改提交消息,而我还需要删除不必要的文件

这可能吗?

不,
git commit--amend
允许您向上次提交添加新的修改。当您使用
-m
参数时,它只更新提交消息

但是,与其尝试从索引中
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
现在只要刷新你的PR页面,它就会自动更新,用新的替换错误的提交

(*假设这是您的功能分支,您可以在其上强制推送,而不会中断其他人的工作。如果我在此处出错,请更正我)