{"thread":{"id":"36711","subject":"untracked file deleted from the master branch, when checked out to it from a local branch","startedAt":"2014-05-20T15:38:42Z","lastAt":"2014-05-21T10:21:40Z","messageCount":10,"participants":["Arup Rakshit","Marius Storm-Olsen","Junio C Hamano","Sergei Organov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"242278","messageId":"2525467.KRXv8a3gWS@linux-wzza.site","threadId":"36711","inReplyTo":null,"subject":"untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Arup Rakshit","fromEmail":"aruprakshit@rocketmail.com","sentAt":"2014-05-20T15:38:42Z","receivedAt":"2014-05-20T15:38:42Z","isPatch":false,"sender":{"key":"aruprakshit@rocketmail.com","avatar":"https://gravatar.com/avatar/a05a6142b0941fafb88c96b156982deb8e49e863ae7803d15c5147276fdeff92?d=mp&s=160"},"body":"I was following some tutorial (http://gitref.org/branching/#merge) - and doing \nit in my console :\n\nArup-iMac:arup_git shreyas$ git status\n# On branch master\nnothing to commit, working directory clean\nArup-iMac:arup_git shreyas$ touch test.rb\nArup-iMac:arup_git shreyas$ ls\ngit_1.txttest.rb\nArup-iMac:arup_git shreyas$ cat test.rb\nArup-iMac:arup_git shreyas$ vi test.rb\nArup-iMac:arup_git shreyas$ cat test.rb\nclass Foo\n  def self.bar\n    12\n  end\nend\n\nFoo.bar\n***********HERE I switched to a NEW Branch****************\nArup-iMac:arup_git shreyas$ git checkout -b change_class\nSwitched to a new branch 'change_class'\nArup-iMac:arup_git shreyas$ ls\ngit_1.txttest.rb\nArup-iMac:arup_git shreyas$ vi test.rb\nArup-iMac:arup_git shreyas$ head -1 test.rb\nclass Fooo\nArup-iMac:arup_git shreyas$ head -2 test.rb\nclass Fooo\n  def self.bar\nArup-iMac:arup_git shreyas$ git commit -am 'changed the class name'\n# On branch change_class\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#test.rb\nnothing added to commit but untracked files present (use \"git add\" to track)\nArup-iMac:arup_git shreyas$ git add test.rb\nArup-iMac:arup_git shreyas$ git commit -am 'changed the class name'\n[change_class 2d40033] changed the class name\n 1 file changed, 7 insertions(+)\n create mode 100644 test.rb\nArup-iMac:arup_git shreyas$ cat test.rb\nclass Fooo\n  def self.bar\n    12\n  end\nend\n\nFooo.bar\nArup-iMac:arup_git shreyas$ git checkout master\nSwitched to branch 'master'\nArup-iMac:arup_git shreyas$ git mv test.rb ruby.rb\nfatal: bad source, source=test.rb, destination=ruby.rb\nArup-iMac:arup_git shreyas$ git mv -h\nusage: git mv [options] <source>... <destination>\n\n    -v, --verbose         be verbose\n    -n, --dry-run         dry run\n    -f, --force           force move/rename even if target exists\n    -k                    skip move/rename errors\n|--------------------------------------------------------------------------------------------------------------|\n********FROM MASTER BRACH WHY THE FILE test.rb DELETED?***********\nArup-iMac:arup_git shreyas$ ls\ngit_1.txt\nArup-iMac:arup_git shreyas$ \n\n-- \n===============\nRegards,\nArup Rakshit\n"},{"id":"242282","messageId":"1949847.AaDQEtxZHd@linux-wzza.site","threadId":"36711","inReplyTo":"537B8959.7090100@gmail.com","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Arup Rakshit","fromEmail":"aruprakshit@rocketmail.com","sentAt":"2014-05-20T16:03:55Z","receivedAt":"2014-05-20T16:03:55Z","isPatch":false,"sender":{"key":"aruprakshit@rocketmail.com","avatar":"https://gravatar.com/avatar/a05a6142b0941fafb88c96b156982deb8e49e863ae7803d15c5147276fdeff92?d=mp&s=160"},"body":"On Tuesday, May 20, 2014 11:56:57 AM you wrote:\n> On 5/20/2014 10:38 AM, Arup Rakshit wrote:\n> > I was following some tutorial (http://gitref.org/branching/#merge) - and\n> > doing it in my console :\n\n> \n> Because you never committed the original file to the master branch\n> before you created and switched to the change_class branch.\n> \n> You're missing\n>      git add test.rb\n>      git commit -m \"initial version of test.rb\"\n> before you switch branches the first time.\n\nHum, But when I create a new branch from master, then it came to the new \nbranch, but deleted from the master. Shouldn't it also not come to the new \nlocal branch also. That's how I expected.\n\n-- \n===============\nRegards,\nArup Rakshit\n"},{"id":"242281","messageId":"537B8959.7090100@gmail.com","threadId":"36711","inReplyTo":"2525467.KRXv8a3gWS@linux-wzza.site","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Marius Storm-Olsen","fromEmail":"mstormo@gmail.com","sentAt":"2014-05-20T16:56:57Z","receivedAt":"2014-05-20T16:56:57Z","isPatch":false,"sender":{"key":"mstormo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1500?v=4"},"body":"On 5/20/2014 10:38 AM, Arup Rakshit wrote:\n> I was following some tutorial (http://gitref.org/branching/#merge) - and doing\n> it in my console :\n>\n> Arup-iMac:arup_git shreyas$ git status\n> # On branch master\n> nothing to commit, working directory clean\n> Arup-iMac:arup_git shreyas$ touch test.rb\n> Arup-iMac:arup_git shreyas$ ls\n> git_1.txttest.rb\n> Arup-iMac:arup_git shreyas$ cat test.rb\n> Arup-iMac:arup_git shreyas$ vi test.rb\n> Arup-iMac:arup_git shreyas$ cat test.rb\n> class Foo\n>    def self.bar\n>      12\n>    end\n> end\n>\n> Foo.bar\n> ***********HERE I switched to a NEW Branch****************\n...\n> ********FROM MASTER BRACH WHY THE FILE test.rb DELETED?***********\n> Arup-iMac:arup_git shreyas$ ls\n> git_1.txt\n\nBecause you never committed the original file to the master branch \nbefore you created and switched to the change_class branch.\n\nYou're missing\n     git add test.rb\n     git commit -m \"initial version of test.rb\"\nbefore you switch branches the first time.\n\n-- \n.marius\n"},{"id":"242284","messageId":"537B8BA9.7060207@storm-olsen.com","threadId":"36711","inReplyTo":"1949847.AaDQEtxZHd@linux-wzza.site","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Marius Storm-Olsen","fromEmail":"marius@storm-olsen.com","sentAt":"2014-05-20T17:06:49Z","receivedAt":"2014-05-20T17:06:49Z","isPatch":false,"sender":{"key":"marius@storm-olsen.com","avatar":"https://avatars.githubusercontent.com/u/1500?v=4"},"body":"On 5/20/2014 11:03 AM, Arup Rakshit wrote:\n> On Tuesday, May 20, 2014 11:56:57 AM you wrote:\n>> On 5/20/2014 10:38 AM, Arup Rakshit wrote:\n>>> I was following some tutorial (http://gitref.org/branching/#merge) - and\n>>> doing it in my console :\n>\n>>\n>> Because you never committed the original file to the master branch\n>> before you created and switched to the change_class branch.\n>>\n>> You're missing\n>>       git add test.rb\n>>       git commit -m \"initial version of test.rb\"\n>> before you switch branches the first time.\n>\n> Hum, But when I create a new branch from master, then it came to the new\n> branch, but deleted from the master. Shouldn't it also not come to the new\n> local branch also. That's how I expected.\n\nIt never \"came to the new branch\", as it was never version controlled, \nit was an untracked file left behind when you switched branches.\n\nOnce you added it to the new branch, change_class, it became a version \ncontrolled file, and since you moved to a branch without that file (the \npristine clean master branch), git removed it. (your version history \nsays that change_class contains test.rb and master does not.)\n\n-- \n.marius\n"},{"id":"242297","messageId":"2726779.MFtIaLB4b4@linux-wzza.site","threadId":"36711","inReplyTo":"537B8BA9.7060207@storm-olsen.com","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Arup Rakshit","fromEmail":"aruprakshit@rocketmail.com","sentAt":"2014-05-20T17:20:17Z","receivedAt":"2014-05-20T17:20:17Z","isPatch":false,"sender":{"key":"aruprakshit@rocketmail.com","avatar":"https://gravatar.com/avatar/a05a6142b0941fafb88c96b156982deb8e49e863ae7803d15c5147276fdeff92?d=mp&s=160"},"body":"On Tuesday, May 20, 2014 12:06:49 PM you wrote:\n\n> \n> It never \"came to the new branch\", as it was never version controlled,\n> it was an untracked file left behind when you switched branches.\n> \n> Once you added it to the new branch, change_class, it became a version\n> controlled file, \n\nThis is still  didn't get it. If an untracked file didn't come in the new \nbranch, how would I able to add it to stage ? I am not getting this part. You \nare right, but I am not able to understand this one, my bad! :(\n\n-- \n===============\nRegards,\nArup Rakshit\n"},{"id":"242305","messageId":"2654529.8c5AhJCJsq@linux-wzza.site","threadId":"36711","inReplyTo":"xmqqk39gz4tw.fsf@gitster.dls.corp.google.com","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Arup Rakshit","fromEmail":"aruprakshit@rocketmail.com","sentAt":"2014-05-20T17:40:47Z","receivedAt":"2014-05-20T17:40:47Z","isPatch":false,"sender":{"key":"aruprakshit@rocketmail.com","avatar":"https://gravatar.com/avatar/a05a6142b0941fafb88c96b156982deb8e49e863ae7803d15c5147276fdeff92?d=mp&s=160"},"body":"On Tuesday, May 20, 2014 11:24:11 AM you wrote:\n> Arup Rakshit <aruprakshit@rocketmail.com> writes:\n> \n> Untracked files and modifications to files in your working directory\n> do not belong to your current branch.  This is to allow you, after\n> starting to work on one branch then realizing that the changes and\n> additions you are making do not belong there, to switch to a more\n> appropriate branch at that point without losing your work so far,\n> taking these changes and additions with you to the branch you want\n> to commit your changes to.\n> \nNow, It makes sense. I gave it another try and this time I walk from back to \nfront.\n\nNow you can see, that I have created, a new file called *file.txt*, in the \n*master branch*. Now I went to a new branch and made some changes there in the \nnewly created file. This time I didn't add it or commit too. I just came back \nto *master branch*. Now if I do *ls*,  can see the file is present in the \n*master* branch.\n\narup@linux-wzza:~/Git_tutorial> ls\ntest.txt\narup@linux-wzza:~/Git_tutorial> echo \"hello\" > file.txt\narup@linux-wzza:~/Git_tutorial> ls\nfile.txt  test.txt\narup@linux-wzza:~/Git_tutorial> git status\n# On branch master\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       file.txt\nnothing added to commit but untracked files present (use \"git add\" to track)\narup@linux-wzza:~/Git_tutorial> cat file.txt\nhello\narup@linux-wzza:~/Git_tutorial> git checkout -b \"file_branch\"\nSwitched to a new branch 'file_branch'\narup@linux-wzza:~/Git_tutorial> cat file.txt\nhello\narup@linux-wzza:~/Git_tutorial> echo \"hello World\" > file.txt\narup@linux-wzza:~/Git_tutorial> cat file.txt\nhello World\narup@linux-wzza:~/Git_tutorial> git status\n# On branch file_branch\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       file.txt\nnothing added to commit but untracked files present (use \"git add\" to track)\narup@linux-wzza:~/Git_tutorial> git checkout master\nSwitched to branch 'master'\narup@linux-wzza:~/Git_tutorial> ls\nfile.txt  test.txt\narup@linux-wzza:~/Git_tutorial> cat file.txt\nhello World\narup@linux-wzza:~/Git_tutorial>\n\n\n-- \n===============\nRegards,\nArup Rakshit\n"},{"id":"242299","messageId":"xmqqk39gz4tw.fsf@gitster.dls.corp.google.com","threadId":"36711","inReplyTo":"2726779.MFtIaLB4b4@linux-wzza.site","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-20T18:24:11Z","receivedAt":"2014-05-20T18:24:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Arup Rakshit <aruprakshit@rocketmail.com> writes:\n\n> On Tuesday, May 20, 2014 12:06:49 PM you wrote:\n>\n>> \n>> It never \"came to the new branch\", as it was never version controlled,\n>> it was an untracked file left behind when you switched branches.\n>> \n>> Once you added it to the new branch, change_class, it became a version\n>> controlled file, \n>\n> This is still  didn't get it. If an untracked file didn't come in the new \n> branch, how would I able to add it to stage ? I am not getting this part. You \n> are right, but I am not able to understand this one, my bad! :(\n\nUntracked files and modifications to files in your working directory\ndo not belong to your current branch.  This is to allow you, after\nstarting to work on one branch then realizing that the changes and\nadditions you are making do not belong there, to switch to a more\nappropriate branch at that point without losing your work so far,\ntaking these changes and additions with you to the branch you want\nto commit your changes to.\n"},{"id":"242302","messageId":"537B9F14.3030403@gmail.com","threadId":"36711","inReplyTo":"2726779.MFtIaLB4b4@linux-wzza.site","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Marius Storm-Olsen","fromEmail":"mstormo@gmail.com","sentAt":"2014-05-20T18:29:40Z","receivedAt":"2014-05-20T18:29:40Z","isPatch":false,"sender":{"key":"mstormo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1500?v=4"},"body":"On 5/20/2014 12:20 PM, Arup Rakshit wrote:\n> On Tuesday, May 20, 2014 12:06:49 PM you wrote:\n>\n>>\n>> It never \"came to the new branch\", as it was never version controlled,\n>> it was an untracked file left behind when you switched branches.\n>>\n>> Once you added it to the new branch, change_class, it became a version\n>> controlled file,\n>\n> This is still  didn't get it. If an untracked file didn't come in the new\n> branch, how would I able to add it to stage ? I am not getting this part. You\n> are right, but I am not able to understand this one, my bad! :(\n\nOk, step by step:\n\nYou've created test.rd, that was never added to the git repo. (You never \ncommitted it to the master branch.)\n\n > ***********HERE I switched to a NEW Branch****************\n > Arup-iMac:arup_git shreyas$ git checkout -b change_class\n > Switched to a new branch 'change_class'\n > Arup-iMac:arup_git shreyas$ ls\n > git_1.txt test.rb\n\ntest.rd is untracked, so still there. Git doesn't touch untracked files.\n\n\n > Arup-iMac:arup_git shreyas$ vi test.rb\n > Arup-iMac:arup_git shreyas$ head -1 test.rb\n > class Fooo\n > Arup-iMac:arup_git shreyas$ head -2 test.rb\n > class Fooo\n >    def self.bar\n\nYou modified it\n\n\n > Arup-iMac:arup_git shreyas$ git commit -am 'changed the class name'\n > # On branch change_class\n > # Untracked files:\n > #   (use \"git add <file>...\" to include in what will be committed)\n > #\n > #test.rb\n > nothing added to commit but untracked files present (use \"git add\" to \ntrack)\n\nYou did nothing here..\n\n\n > Arup-iMac:arup_git shreyas$ git add test.rb\n > Arup-iMac:arup_git shreyas$ git commit -am 'changed the class name'\n > [change_class 2d40033] changed the class name\n >   1 file changed, 7 insertions(+)\n >   create mode 100644 test.rb\n\nYour previously untracked file has now been checked in. It's no longer \nuntracked, so now Git cares.\n\n\n > Arup-iMac:arup_git shreyas$ cat test.rb\n > class Fooo\n >    def self.bar\n >      12\n >    end\n > end\n >\n > Fooo.bar\n > Arup-iMac:arup_git shreyas$ git checkout master\n > Switched to branch 'master'\n\nYou switched back to master branch, which contains no test.rb (as it's \nclean and has never been committed to), so therefore Git removes the \nfile, since the now tracked test.rb shouldn't be on the master branch.\n\n-- \n.marius\n"},{"id":"242306","messageId":"537BA2A9.3020708@gmail.com","threadId":"36711","inReplyTo":"2654529.8c5AhJCJsq@linux-wzza.site","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Marius Storm-Olsen","fromEmail":"mstormo@gmail.com","sentAt":"2014-05-20T18:44:57Z","receivedAt":"2014-05-20T18:44:57Z","isPatch":false,"sender":{"key":"mstormo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1500?v=4"},"body":"On 5/20/2014 12:40 PM, Arup Rakshit wrote:\n> On Tuesday, May 20, 2014 11:24:11 AM you wrote:\n>> Arup Rakshit <aruprakshit@rocketmail.com> writes:\n>>\n>> Untracked files and modifications to files in your working directory\n>> do not belong to your current branch.  This is to allow you, after\n>> starting to work on one branch then realizing that the changes and\n>> additions you are making do not belong there, to switch to a more\n>> appropriate branch at that point without losing your work so far,\n>> taking these changes and additions with you to the branch you want\n>> to commit your changes to.\n>>\n> Now, It makes sense. I gave it another try and this time I walk from back to\n> front.\n>\n> Now you can see, that I have created, a new file called *file.txt*, in the\n> *master branch*.\n\nNO, you didn't.\n\n > arup@linux-wzza:~/Git_tutorial> git status\n > # On branch master\n > # Untracked files:\n > #   (use \"git add <file>...\" to include in what will be committed)\n > #\n > #       file.txt\n\nSee that file.txt is listed under \"Untracked files\"?\nGit sees the file, but since you haven't added it with \"git add\", it's \nuntracked and Git doesn't care about it.\n\nIt lists it with the status command, so you will see that it's not yet \ntracked.\n\n-- \n.marius\n"},{"id":"242368","messageId":"8761kz5t57.fsf@osv.gnss.ru","threadId":"36711","inReplyTo":"2654529.8c5AhJCJsq@linux-wzza.site","subject":"Re: untracked file deleted from the master branch, when checked out to it from a local branch","fromName":"Sergei Organov","fromEmail":"osv@javad.com","sentAt":"2014-05-21T10:21:40Z","receivedAt":"2014-05-21T10:21:40Z","isPatch":false,"sender":{"key":"osv@javad.com","avatar":null},"body":"Arup Rakshit <aruprakshit@rocketmail.com> writes:\n\n\n[...]\n\n> Now you can see, that I have created, a new file called *file.txt*, in the \n> *master branch*.\n\nAnd here is your basic misunderstanding. You've created file.txt indeed,\nbut not in the *master branch* (or any branch). You've created it in the\nworking directory. Only after you add/commit it, will it be \"created\" in\nthe branch that is checked out at this time. Until then, git won't touch\nthe file when you switch between branches.\n\n-- Sergey.\n"}]}