首页 > 解决方案 > With Git how do I insert a modified file into the master branch

问题描述

I just have a master branch, I need to go back to an earlier tag to modify the pom.xml file and then release it to Maven Central. So I want to edit the file and then commit it, but if I do that and then swap back to the latest commit I assume I will see that modified file as the latest file when I do git checkout back to HEAD, which would be wrong.

So how do I insert a modified file into the master branch?

git checkout tag/v2.2.5
edit pom.xml
# commit somehow, and push to remote
mvn release
git checkout

At this point, the current code should look the same as it did to start with.

标签: gitmaven

解决方案


Okay from the comments it seems is not possible, so as the purpose was to make a change to the build file so that I could just deploy the builds to the Maven repository I did the following instead:

git checkout tag/v2.2.5
edit pom.xml
mvn clean deploy -Prelease
git reset --hard
git checkout master

So I used git to go to the right place and make the edit, I did the build and then just discarded the edit.


推荐阅读