Basic git question #22794
-
Hi, I never had git , just got started, to my understanding the first thing is to create the repo,
After I did the first commit, I realized that some of the files had sensitive information in them , I still need these files to get tracked, so I edited them , remove the sensitive info to a different untracked file , did git add again and git commit
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 2 replies
-
isaacdvory:
isaacdvory:
It’s a local repository, yes.
isaacdvory:
In general: You can change the current HEAD commit by However, I strongly recommend you do not do that on a live server, even if you were a highly experienced git user. What I suggest you do is copy the files to another system and create the repository there. That way any experiments or mistakes won’t break your live server.
isaacdvory:
By default, yes. You can use
isaacdvory:
You can do that, assuming there are no more history modifications (if there are, a simple However, you might want to consider setting up a deployment step, that only copies the files that are needed onto your live server instead of having the whole repository there. But what’s best there really depends on what your specific needs are. 🙂 |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your answer. then on the live server I would need to just
thanks. |
Beta Was this translation helpful? Give feedback.
-
isaacdvory:
Ah yes, in that case it’ll be difficult to manually check everything. Though it also makes me wonder if all those files are part of the same project, or if you might want to split them into smaller sets. But I don’t know your situation. 🙂
isaacdvory:
Yes, that’s what I recommend, because that way any experiments or mistakes while you figure things out won’t affect the live server (which I assume you want to keep running without interruptions). For git it doesn’t matter either way, git just tracks the files, wherever you tell it to. 😉
isaacdvory:
Yes. Keep in mind that this will delete the complete history of the repository, so I usually wouldn’t recommend it. But you said you had just one commit that you explicitly want to get rid of and the current fixed state, so in this case it seems appropriate to simply start over.
isaacdvory:
That would work, yes.
isaacdvory:
“Deployment” is a generic term, in IT it refers to making something (like a software of website) operational. Pulling the latest version from git on your live server would be one possible way to deploy your website, if the server just needs the files from git as they are. What I’m questioning is whether that’s the best way to do it. Again, I don’t know your system, so I can’t say for sure. But for example you could alternatively create a TAR or ZIP archive of all the files in your repository using I recently read a report about companies that unintentionally published the whole git history with their websites, and in some cases those histories contained secrets, so I had to think of that here. 😉 |
Beta Was this translation helpful? Give feedback.
-
Thanks again. |
Beta Was this translation helpful? Give feedback.
-
isaacdvory:
In that case a push/pull workflow should work just fine. Just make sure your web server is not going to serve the |
Beta Was this translation helpful? Give feedback.
-
Hi :slight_smile: it’s been a while and I need some help again please. /home/dev_staging/staging/ I made sure it’s not being served by nginx. Went back to my live server, I have a staging folder there as well in /home/deployment/site/ then did “git staging fetch master”, it asks for a password and then :
Seems good right? so why when I do git status , it just shows that all my files are untracked? is that normal? shouldn’t it have recognized that it’s the same files and show my with files are different etc…? or I should still do in this second staging server the same as I did in the first staging? add .gitignore, do git add , commit ? I don’t understand how do I start working with this normally as everybody works with git 😦 |
Beta Was this translation helpful? Give feedback.
-
isaacdvory:
That is expected:
After that you should see any differences with the working tree files. A word of caution: I’d be worried about leaving an SSH key on the live server. It looks like you use it to do a regular login and then access files, so someone who steals it might be able to get other data, too. I assume the live server has a higher attack surface (especially if it’s on the internet) than your work system or the staging server, so I’d rather do login the other way around and push to the live server. 😉 |
Beta Was this translation helpful? Give feedback.
-
Thanks, I did the reset now, I think it’s fine. thanks again |
Beta Was this translation helpful? Give feedback.
-
Hi, I got some error message when I tried to push from the live server, that I understand is because I didn’t create a bare repo on the repo server, so I had to do this: “git config receive.denyCurrentBranch ignore” in the repo server On branch master and I don’t understand what do I need to do now? commit again ? |
Beta Was this translation helpful? Give feedback.
-
That’s because you pushed changes from the live server to the staging server. Pushing with As usual what to do depends on which version you actually want to keep. If you want to keep the version of the staging server, you should discard the commit made on the live server. If you want to keep the version from the live server, call That said, based on what you said about the intended workflow I’m confused why you made a commit on the live server at all. Didn’t you want to use the code exactly as it has been tested in staging? |
Beta Was this translation helpful? Give feedback.
-
It’s because between the time it took me to move files manually to the staging server and setting up everything to work, some files already changed in the live server, so after fetching from the staging to live , I saw the files that are newer in the live server, added them, committed and pushed |
Beta Was this translation helpful? Give feedback.
-
so how do I actually do the git checkout? |
Beta Was this translation helpful? Give feedback.
-
You can give multiple files at once. Alternatively you could use |
Beta Was this translation helpful? Give feedback.
git checkout FILE
will overwrite the working tree file with the current HEAD version, so for example:You can give multiple files at once. Alternatively you could use
git reset --hard HEAD
to reset all files in the working tree to the HEAD state. I prefer the checkout approach because it does less damage in case of a mistake. 😉