I am trying to get specific version in git and commit it as the current version. Consider this example scenario:
tag : v2 (current version)
files : 1.txt,2.txt,3.txt
tag : v1
files : 55.xml,33.yml
I am trying to switch to tag v1 and make it as my current version (get this specific version)
By searching web, i could able to find out way to get all the files
git checkout tag_name
# ex. git checkout v1
And this actually fetches the files from the specific version and loads into my working directory.
But i cannot commit the existing files and push it back to server.
(When it try to push, it shows like no changes pending)
It shows no changes pending because there are no changes. If you want
masteron the remote to point tov1, you can do anupdate-refor areseton the remote. If you want to create a new commit which is a child ofv2that has the same tree asv1, you could do amerge. What exactly is it that you want to do? Is the remote a bare repo, or is it a working directory? If the former, you should do nothing and anyone who wants to see the files atv1should checkoutv1. If the latter, you should simply checkoutv1on the remote but make no new commits.From your comments, it sounds like you want to make a new commit to the remote repo which has the same file content as the tag
v1. It really is best to simply useupdate-refon the remote repo to reset it back tov1, but it is certainly possible to make a new commit. One approach is:This computes the tree of
v1, invokes commit-tree with that argument to create a new commit object whose parent isv2(or use HEAD, or whatever you want to be the parent of the new commit) using the commit log “Resetting repo to v1” and then resets the repo so that HEAD points to the new commit. After doing this, you should be able to push to the repo. It might be simpler to just do apulland merge in the old tree, but that may require a fair bit of manual intervention resolving conflicts.