简体   繁体   English

如何在 git 存储库中缩进我的代码并在没有历史记录的情况下提交和合并?

[英]How can I indent my code in a git repo and commit and merge without history?

I have a git repo with so many C language code files, which are bad formatted.我有一个 git 存储库,其中包含许多 C 语言代码文件,这些文件格式错误。

So can I use indent tool to reformat my source files, and commit them and push it to gitlab repo without changing the history?那么我可以使用缩进工具重新格式化我的源文件,并提交它们并将其推送到 gitlab 存储库而不更改历史记录吗?

Of course normal commit and push and PR workflow works, but the most recent history of each file will be destoried and display one same message.当然,正常的提交、推送和 PR 工作流可以工作,但是每个文件的最新历史记录将被破坏并显示相同的消息。

Thanks.谢谢。

While you can't make those changes without changing the history, you can make those changes and put them in an existing commit.虽然您无法在不更改历史记录的情况下进行这些更改,但您可以进行这些更改并将它们放入现有提交中。

git commit --amend will add any staged changes to the most recent commit on the current branch. git commit --amend会将任何阶段性更改添加到当前分支上的最新提交。

The commit message will remain the same but the commit hash will change.提交消息将保持不变,但提交 hash 将更改。

In order to push an amended commit you need to provide the -f flag to force your changes to the remote repository, since the hash changed.由于 hash 已更改,因此为了推送修改后的提交,您需要提供-f标志以强制您对远程存储库进行更改。 (Be careful with force pushes, if anyone else has pushed to the repository since you last pulled their changes will be erased.) (小心强制推送,如果自上次拉取后有其他人推送到存储库,他们的更改将被删除。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM