Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does my commit goes if I checkout tag and commit?

Tags:

git

In GIT, if I checkout a tag I'll get my working copy to that tag's reference, i.e. the code will represent what I had at that time. I'm I correct?

Now, if I do that, and modify my code and commit. Where is that commit going? Will it sort of 'auto-merge'? Meaning that if I push my commit, someone that clones the repo will also get the fix I did from the tag? Or otherwise, if I switch back to master, will I have the code modification available there?

like image 646
code-gijoe Avatar asked Dec 16 '25 22:12

code-gijoe


2 Answers

The commit is still only stored locally. Only you have a reference to the modified version. If you want to make it available to others, you will also have to do a git push of your code to the given branch.

Your commits are branch-specific, meaning if you change branches after committing, your changes will not carry over. However, when you change back to the branch, the commit will still be there.

like image 145
Igor Avatar answered Dec 19 '25 18:12

Igor


It will not "auto-merge". It is stored in the repository, referenced by HEAD directly. Usually the reference HEAD (the small file in .git, named HEAD) contains the name of the branch, which top-commit reference is updated with every commit. In you case it is a so called "detached HEAD".

You can always save the detached HEAD in a real branch reference: git branch something. Or just checkout another branch and forget about the commits, they will be cleaned up eventually.

like image 25
fork0 Avatar answered Dec 19 '25 20:12

fork0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!