简体   繁体   中英

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.

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.

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