----- Original Message ----- From: dkoleary To: Git for human beings Sent: Monday, June 20, 2016 11:20 PM Subject: [git-users] Changes to a branch affect master even w/o merge?
Hey; Apologies if this is a noob question; but, I'm not that familiar with branching. I'm writing a script to manipulate a bunch of files under a git repo. While working out the script, I figured it'd be best to branch out of the master. $ git status # On branch master nothing to commit (working directory clean) $ git branch * master $ git checkout -b kill_bill Switched to a new branch 'kill_bill' $ git branch * kill_bill master The script moves one file, then updates a couple of parameters in another. So far, everything looks fine. $ git branch * kill_bill master $ git status # On branch kill_bill # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: vhost-old_host.conf -> vhost-default.conf # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: httpd.conf Test complete, I want to blow away the branch, recreate it and start again: However, when I hop back into the master branch, all my changes are there as if I'd run 'git merge' $ git branch * kill_bill master $ git checkout master M CL1/PROD/cl1vproesap281/httpd/httpd.conf D CL1/PROD/cl1vproesap281/httpd/vhost-cl1vproesap281.conf A CL1/PROD/cl1vproesap281/httpd/vhost-default.conf Switched to branch 'master' $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: vhost-cl1vproesap281.conf -> vhost-default.conf # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: httpd.conf # My (admittedly) limited understanding of branching is that I should be able to do anything in kill_bill without having it affect master? Am I doing something wrong? Any help gratefully appreciated. Doug O'Leary The good news: The problem isn't in the branching. The lesser news: You'll need to learn about the staging area a/k/a the Index. This is the area, like an out-box, where you add you finished files. However simply adding them to the out-box / index, doesn't actually commit them (formally) to the repository and its history (with nice commit message etc.) So when you switched back to master, all your changes were still where you left them, rather than 'in the filing cabinet',. You will also see that you hadn't even added your httpd.conf to the index (it's still just shown as a modified file!), so it couldn't even be commited (from the staging area / index) yet. Juts add the files you desire, then commit the package. -- Philip -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.