简体   繁体   中英

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.

So can I use indent tool to reformat my source files, and commit them and push it to gitlab repo without changing the history?

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.

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.

The commit message will remain the same but the commit hash will change.

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. (Be careful with force pushes, if anyone else has pushed to the repository since you last pulled their changes will be erased.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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