Hello,

TL;DR: no, your branch is not polluted, your working directory is in a
dirty state.

A branch is just a pointer to a commit, so if it gets “polluted”, that
would mean your last commit has changed.

What happened is that your changes in the working directory (which, before
you modified your file, is the representation of your last commit) has been
left intact. This is Git's way to protect your work; if, for any reason,
the modified file has been changed on your master branch (like by a
commit+push from a fellow developer), Git would refuse the checkout
altogether for the very same reason: the checkout would overwrite your
uncommitted changes.

Now if you really want to abandon that change, you should reset that file
to the same state as it was in the last commit. Surprisingly (well,
somewhat), this is done by git checkout HEAD:your/modified-file.txt, not by
git reset (as I expected a few years ago). This checkout command will drop
your changes to that file, so when you checkout your master branch, it
won't “pollute” it.

Best,
Gergely

On Tue, Sep 13, 2016, 16:26 Pierre Dutronc <pierre.pas...@gmail.com> wrote:

> Hi,
>
> When I began using Git a few months ago in Windows under WAMP, I found it
> very useful to be able to create a new test branch, alter a few lines of
> code and see how it worked out. If it worked well, I would switch back to
> master and merge the test branch into master. If it did not work well, I
> would just abandon the test branch and continue down a new path in master.
>
> Today, I have switched to linux and a may thus have a newer version of Git
> (I honestly don't remember what I had under Windows). I tried the above
> modus operandi and was surprised because it did not work as expected:
>
> - I left master, created a new branch, and checked out that branch.
> - I altered a few lines of code and saved the file. I did not even commit.
> - I did not like how it turned out so I switched back to master and to my
> surprise the new lines of code were present in the file I had edited while
> being in the other branch. Master had been polluted by the other branch.
>
> My current Git version i 2.7.4. I tried to find out but can't see if
> something changed in the way Git works.
>
> I certainly expected my edit not to be in the file once I had switched
> back to master.
>
> Does anyone understand what is going on? I'd be very grateful for some
> elucidation on this point.
>
> Thanks!
>
> --
> 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.
>

-- 
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.

Reply via email to