I have a build system that takes a git repository, goes back to a specific commit, and then uploads those files some where. Then is goes back to master.
I’m unsure that I’m using the right Git commands, as Git will give me this message whenever I perform a git checkout SHA:
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
The only thing I want to do is to reset my working directory to a specific commit, upload those files, and go back to HEAD/master. I might make a few changes to files when I go to the specific commit SHA (convert XML to JSON or something), but I just want to loose all of those changes when I go back to master. Right now this is my code
git checkout SHA
# do a bunch of conversion and uploading
git checkout master
Is that the preferred way of doing what I want? Will I always be able to do pulls from the origin without getting any file conflicts (I don’t want to keep whatever I’m doing between the checkouts)?
I’m asking because I’m seeing “your master and origin/master diverged” some times, although I’m not sure it’s caused by this.
Thanks in advance.
It’s perfectly OK to do this. When HEAD isn’t corresponding to a branch name it will be shown as a detached HEAD. Nothing wrong with that.