* untracked file deleted from the master branch, when checked out to it from a local branch
@ 2014-05-20 15:38 Arup Rakshit
2014-05-20 16:56 ` Marius Storm-Olsen
0 siblings, 1 reply; 10+ messages in thread
From: Arup Rakshit @ 2014-05-20 15:38 UTC (permalink / raw)
To: git
I was following some tutorial (http://gitref.org/branching/#merge) - and doing
it in my console :
Arup-iMac:arup_git shreyas$ git status
# On branch master
nothing to commit, working directory clean
Arup-iMac:arup_git shreyas$ touch test.rb
Arup-iMac:arup_git shreyas$ ls
git_1.txttest.rb
Arup-iMac:arup_git shreyas$ cat test.rb
Arup-iMac:arup_git shreyas$ vi test.rb
Arup-iMac:arup_git shreyas$ cat test.rb
class Foo
def self.bar
12
end
end
Foo.bar
***********HERE I switched to a NEW Branch****************
Arup-iMac:arup_git shreyas$ git checkout -b change_class
Switched to a new branch 'change_class'
Arup-iMac:arup_git shreyas$ ls
git_1.txttest.rb
Arup-iMac:arup_git shreyas$ vi test.rb
Arup-iMac:arup_git shreyas$ head -1 test.rb
class Fooo
Arup-iMac:arup_git shreyas$ head -2 test.rb
class Fooo
def self.bar
Arup-iMac:arup_git shreyas$ git commit -am 'changed the class name'
# On branch change_class
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
#test.rb
nothing added to commit but untracked files present (use "git add" to track)
Arup-iMac:arup_git shreyas$ git add test.rb
Arup-iMac:arup_git shreyas$ git commit -am 'changed the class name'
[change_class 2d40033] changed the class name
1 file changed, 7 insertions(+)
create mode 100644 test.rb
Arup-iMac:arup_git shreyas$ cat test.rb
class Fooo
def self.bar
12
end
end
Fooo.bar
Arup-iMac:arup_git shreyas$ git checkout master
Switched to branch 'master'
Arup-iMac:arup_git shreyas$ git mv test.rb ruby.rb
fatal: bad source, source=test.rb, destination=ruby.rb
Arup-iMac:arup_git shreyas$ git mv -h
usage: git mv [options] <source>... <destination>
-v, --verbose be verbose
-n, --dry-run dry run
-f, --force force move/rename even if target exists
-k skip move/rename errors
|--------------------------------------------------------------------------------------------------------------|
********FROM MASTER BRACH WHY THE FILE test.rb DELETED?***********
Arup-iMac:arup_git shreyas$ ls
git_1.txt
Arup-iMac:arup_git shreyas$
--
===============
Regards,
Arup Rakshit
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 15:38 untracked file deleted from the master branch, when checked out to it from a local branch Arup Rakshit
@ 2014-05-20 16:56 ` Marius Storm-Olsen
2014-05-20 16:03 ` Arup Rakshit
0 siblings, 1 reply; 10+ messages in thread
From: Marius Storm-Olsen @ 2014-05-20 16:56 UTC (permalink / raw)
To: Arup Rakshit, git
On 5/20/2014 10:38 AM, Arup Rakshit wrote:
> I was following some tutorial (http://gitref.org/branching/#merge) - and doing
> it in my console :
>
> Arup-iMac:arup_git shreyas$ git status
> # On branch master
> nothing to commit, working directory clean
> Arup-iMac:arup_git shreyas$ touch test.rb
> Arup-iMac:arup_git shreyas$ ls
> git_1.txttest.rb
> Arup-iMac:arup_git shreyas$ cat test.rb
> Arup-iMac:arup_git shreyas$ vi test.rb
> Arup-iMac:arup_git shreyas$ cat test.rb
> class Foo
> def self.bar
> 12
> end
> end
>
> Foo.bar
> ***********HERE I switched to a NEW Branch****************
...
> ********FROM MASTER BRACH WHY THE FILE test.rb DELETED?***********
> Arup-iMac:arup_git shreyas$ ls
> git_1.txt
Because you never committed the original file to the master branch
before you created and switched to the change_class branch.
You're missing
git add test.rb
git commit -m "initial version of test.rb"
before you switch branches the first time.
--
.marius
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 16:56 ` Marius Storm-Olsen
@ 2014-05-20 16:03 ` Arup Rakshit
2014-05-20 17:06 ` Marius Storm-Olsen
0 siblings, 1 reply; 10+ messages in thread
From: Arup Rakshit @ 2014-05-20 16:03 UTC (permalink / raw)
To: git
On Tuesday, May 20, 2014 11:56:57 AM you wrote:
> On 5/20/2014 10:38 AM, Arup Rakshit wrote:
> > I was following some tutorial (http://gitref.org/branching/#merge) - and
> > doing it in my console :
>
> Because you never committed the original file to the master branch
> before you created and switched to the change_class branch.
>
> You're missing
> git add test.rb
> git commit -m "initial version of test.rb"
> before you switch branches the first time.
Hum, But when I create a new branch from master, then it came to the new
branch, but deleted from the master. Shouldn't it also not come to the new
local branch also. That's how I expected.
--
===============
Regards,
Arup Rakshit
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 16:03 ` Arup Rakshit
@ 2014-05-20 17:06 ` Marius Storm-Olsen
2014-05-20 17:20 ` Arup Rakshit
0 siblings, 1 reply; 10+ messages in thread
From: Marius Storm-Olsen @ 2014-05-20 17:06 UTC (permalink / raw)
To: Arup Rakshit, git
On 5/20/2014 11:03 AM, Arup Rakshit wrote:
> On Tuesday, May 20, 2014 11:56:57 AM you wrote:
>> On 5/20/2014 10:38 AM, Arup Rakshit wrote:
>>> I was following some tutorial (http://gitref.org/branching/#merge) - and
>>> doing it in my console :
>
>>
>> Because you never committed the original file to the master branch
>> before you created and switched to the change_class branch.
>>
>> You're missing
>> git add test.rb
>> git commit -m "initial version of test.rb"
>> before you switch branches the first time.
>
> Hum, But when I create a new branch from master, then it came to the new
> branch, but deleted from the master. Shouldn't it also not come to the new
> local branch also. That's how I expected.
It never "came to the new branch", as it was never version controlled,
it was an untracked file left behind when you switched branches.
Once you added it to the new branch, change_class, it became a version
controlled file, and since you moved to a branch without that file (the
pristine clean master branch), git removed it. (your version history
says that change_class contains test.rb and master does not.)
--
.marius
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 17:06 ` Marius Storm-Olsen
@ 2014-05-20 17:20 ` Arup Rakshit
2014-05-20 18:24 ` Junio C Hamano
2014-05-20 18:29 ` Marius Storm-Olsen
0 siblings, 2 replies; 10+ messages in thread
From: Arup Rakshit @ 2014-05-20 17:20 UTC (permalink / raw)
To: git
On Tuesday, May 20, 2014 12:06:49 PM you wrote:
>
> It never "came to the new branch", as it was never version controlled,
> it was an untracked file left behind when you switched branches.
>
> Once you added it to the new branch, change_class, it became a version
> controlled file,
This is still didn't get it. If an untracked file didn't come in the new
branch, how would I able to add it to stage ? I am not getting this part. You
are right, but I am not able to understand this one, my bad! :(
--
===============
Regards,
Arup Rakshit
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 17:20 ` Arup Rakshit
@ 2014-05-20 18:24 ` Junio C Hamano
2014-05-20 17:40 ` Arup Rakshit
2014-05-20 18:29 ` Marius Storm-Olsen
1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2014-05-20 18:24 UTC (permalink / raw)
To: Arup Rakshit; +Cc: git
Arup Rakshit <aruprakshit@rocketmail.com> writes:
> On Tuesday, May 20, 2014 12:06:49 PM you wrote:
>
>>
>> It never "came to the new branch", as it was never version controlled,
>> it was an untracked file left behind when you switched branches.
>>
>> Once you added it to the new branch, change_class, it became a version
>> controlled file,
>
> This is still didn't get it. If an untracked file didn't come in the new
> branch, how would I able to add it to stage ? I am not getting this part. You
> are right, but I am not able to understand this one, my bad! :(
Untracked files and modifications to files in your working directory
do not belong to your current branch. This is to allow you, after
starting to work on one branch then realizing that the changes and
additions you are making do not belong there, to switch to a more
appropriate branch at that point without losing your work so far,
taking these changes and additions with you to the branch you want
to commit your changes to.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 18:24 ` Junio C Hamano
@ 2014-05-20 17:40 ` Arup Rakshit
2014-05-20 18:44 ` Marius Storm-Olsen
2014-05-21 10:21 ` Sergei Organov
0 siblings, 2 replies; 10+ messages in thread
From: Arup Rakshit @ 2014-05-20 17:40 UTC (permalink / raw)
To: git
On Tuesday, May 20, 2014 11:24:11 AM you wrote:
> Arup Rakshit <aruprakshit@rocketmail.com> writes:
>
> Untracked files and modifications to files in your working directory
> do not belong to your current branch. This is to allow you, after
> starting to work on one branch then realizing that the changes and
> additions you are making do not belong there, to switch to a more
> appropriate branch at that point without losing your work so far,
> taking these changes and additions with you to the branch you want
> to commit your changes to.
>
Now, It makes sense. I gave it another try and this time I walk from back to
front.
Now you can see, that I have created, a new file called *file.txt*, in the
*master branch*. Now I went to a new branch and made some changes there in the
newly created file. This time I didn't add it or commit too. I just came back
to *master branch*. Now if I do *ls*, can see the file is present in the
*master* branch.
arup@linux-wzza:~/Git_tutorial> ls
test.txt
arup@linux-wzza:~/Git_tutorial> echo "hello" > file.txt
arup@linux-wzza:~/Git_tutorial> ls
file.txt test.txt
arup@linux-wzza:~/Git_tutorial> git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file.txt
nothing added to commit but untracked files present (use "git add" to track)
arup@linux-wzza:~/Git_tutorial> cat file.txt
hello
arup@linux-wzza:~/Git_tutorial> git checkout -b "file_branch"
Switched to a new branch 'file_branch'
arup@linux-wzza:~/Git_tutorial> cat file.txt
hello
arup@linux-wzza:~/Git_tutorial> echo "hello World" > file.txt
arup@linux-wzza:~/Git_tutorial> cat file.txt
hello World
arup@linux-wzza:~/Git_tutorial> git status
# On branch file_branch
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file.txt
nothing added to commit but untracked files present (use "git add" to track)
arup@linux-wzza:~/Git_tutorial> git checkout master
Switched to branch 'master'
arup@linux-wzza:~/Git_tutorial> ls
file.txt test.txt
arup@linux-wzza:~/Git_tutorial> cat file.txt
hello World
arup@linux-wzza:~/Git_tutorial>
--
===============
Regards,
Arup Rakshit
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 17:40 ` Arup Rakshit
@ 2014-05-20 18:44 ` Marius Storm-Olsen
2014-05-21 10:21 ` Sergei Organov
1 sibling, 0 replies; 10+ messages in thread
From: Marius Storm-Olsen @ 2014-05-20 18:44 UTC (permalink / raw)
To: Arup Rakshit, git
On 5/20/2014 12:40 PM, Arup Rakshit wrote:
> On Tuesday, May 20, 2014 11:24:11 AM you wrote:
>> Arup Rakshit <aruprakshit@rocketmail.com> writes:
>>
>> Untracked files and modifications to files in your working directory
>> do not belong to your current branch. This is to allow you, after
>> starting to work on one branch then realizing that the changes and
>> additions you are making do not belong there, to switch to a more
>> appropriate branch at that point without losing your work so far,
>> taking these changes and additions with you to the branch you want
>> to commit your changes to.
>>
> Now, It makes sense. I gave it another try and this time I walk from back to
> front.
>
> Now you can see, that I have created, a new file called *file.txt*, in the
> *master branch*.
NO, you didn't.
> arup@linux-wzza:~/Git_tutorial> git status
> # On branch master
> # Untracked files:
> # (use "git add <file>..." to include in what will be committed)
> #
> # file.txt
See that file.txt is listed under "Untracked files"?
Git sees the file, but since you haven't added it with "git add", it's
untracked and Git doesn't care about it.
It lists it with the status command, so you will see that it's not yet
tracked.
--
.marius
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 17:40 ` Arup Rakshit
2014-05-20 18:44 ` Marius Storm-Olsen
@ 2014-05-21 10:21 ` Sergei Organov
1 sibling, 0 replies; 10+ messages in thread
From: Sergei Organov @ 2014-05-21 10:21 UTC (permalink / raw)
To: Arup Rakshit; +Cc: git
Arup Rakshit <aruprakshit@rocketmail.com> writes:
[...]
> Now you can see, that I have created, a new file called *file.txt*, in the
> *master branch*.
And here is your basic misunderstanding. You've created file.txt indeed,
but not in the *master branch* (or any branch). You've created it in the
working directory. Only after you add/commit it, will it be "created" in
the branch that is checked out at this time. Until then, git won't touch
the file when you switch between branches.
-- Sergey.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: untracked file deleted from the master branch, when checked out to it from a local branch
2014-05-20 17:20 ` Arup Rakshit
2014-05-20 18:24 ` Junio C Hamano
@ 2014-05-20 18:29 ` Marius Storm-Olsen
1 sibling, 0 replies; 10+ messages in thread
From: Marius Storm-Olsen @ 2014-05-20 18:29 UTC (permalink / raw)
To: Arup Rakshit, git
On 5/20/2014 12:20 PM, Arup Rakshit wrote:
> On Tuesday, May 20, 2014 12:06:49 PM you wrote:
>
>>
>> It never "came to the new branch", as it was never version controlled,
>> it was an untracked file left behind when you switched branches.
>>
>> Once you added it to the new branch, change_class, it became a version
>> controlled file,
>
> This is still didn't get it. If an untracked file didn't come in the new
> branch, how would I able to add it to stage ? I am not getting this part. You
> are right, but I am not able to understand this one, my bad! :(
Ok, step by step:
You've created test.rd, that was never added to the git repo. (You never
committed it to the master branch.)
> ***********HERE I switched to a NEW Branch****************
> Arup-iMac:arup_git shreyas$ git checkout -b change_class
> Switched to a new branch 'change_class'
> Arup-iMac:arup_git shreyas$ ls
> git_1.txt test.rb
test.rd is untracked, so still there. Git doesn't touch untracked files.
> Arup-iMac:arup_git shreyas$ vi test.rb
> Arup-iMac:arup_git shreyas$ head -1 test.rb
> class Fooo
> Arup-iMac:arup_git shreyas$ head -2 test.rb
> class Fooo
> def self.bar
You modified it
> Arup-iMac:arup_git shreyas$ git commit -am 'changed the class name'
> # On branch change_class
> # Untracked files:
> # (use "git add <file>..." to include in what will be committed)
> #
> #test.rb
> nothing added to commit but untracked files present (use "git add" to
track)
You did nothing here..
> Arup-iMac:arup_git shreyas$ git add test.rb
> Arup-iMac:arup_git shreyas$ git commit -am 'changed the class name'
> [change_class 2d40033] changed the class name
> 1 file changed, 7 insertions(+)
> create mode 100644 test.rb
Your previously untracked file has now been checked in. It's no longer
untracked, so now Git cares.
> Arup-iMac:arup_git shreyas$ cat test.rb
> class Fooo
> def self.bar
> 12
> end
> end
>
> Fooo.bar
> Arup-iMac:arup_git shreyas$ git checkout master
> Switched to branch 'master'
You switched back to master branch, which contains no test.rb (as it's
clean and has never been committed to), so therefore Git removes the
file, since the now tracked test.rb shouldn't be on the master branch.
--
.marius
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-05-21 10:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-20 15:38 untracked file deleted from the master branch, when checked out to it from a local branch Arup Rakshit
2014-05-20 16:56 ` Marius Storm-Olsen
2014-05-20 16:03 ` Arup Rakshit
2014-05-20 17:06 ` Marius Storm-Olsen
2014-05-20 17:20 ` Arup Rakshit
2014-05-20 18:24 ` Junio C Hamano
2014-05-20 17:40 ` Arup Rakshit
2014-05-20 18:44 ` Marius Storm-Olsen
2014-05-21 10:21 ` Sergei Organov
2014-05-20 18:29 ` Marius Storm-Olsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).