Re: Working directory managment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Anjib Mulepati <anjibcs@xxxxxxxxxxx> writes:

> I was reading Git Community Book and came across following definition
> for working directory
>
> The Working Directory
>
> The Git 'working directory' is the directory that holds the current
> checkout of the files you are working on. Files in this directory are
> often removed or replaced by Git as you switch branches - this is
> normal. All your history is stored in the Git Directory; the working
> directory is simply a temporary checkout place where you can modify
> the files until your next commit.
>
> What does it mean by this " Files in this directory are often removed
> or replaced by Git as you switch branches"?
>
>> I think the common terminology for the concept the above describes is "the
>> working tree".
>>
>>> And does working directory is just a directory we get with $pwd ?
>> After you clone, you have one directory that contains all the files from
>> one specific version in it.  The files may be organized into directory
>> hierarchy, but there is a single top-level directory.
>>
>> That is the "working tree".  When we want to be absolutely clear, we may
>> even say "the top of the working tree", even though it may be redundant.
>>
>> If you are at such a directory, $(pwd) may match it.  If you chdir to a
>> subdirectory from there, e.g. "cd Documentation", $(pwd) and the top of
>> the working tree will of course disagree.
>>
>> The files checked out in the working tree represent the contents of the
>> version that was checked out, plus modifications you make locally.  When
>> you check out a different branch (people coming from svn background may
>> say "switch branch", but it is the same thing), the working tree will need
>> to represent the contents of the version at the tip of that different
>> branch.  If you have a file in the current branch but not in that
>> different branch you are checking out, that file has to go away.  If you
>> do not have a file in the current branch but not in that different branch
>> you are checking out, that file needs to be created in the working tree.
>> If the contents of a file is different between your current branch and the
>> branch you are checking out, the file in the working tree needs to be
>> updated to match that of the branch you are checking out. That is what the
>> "... are often removed or replaced" part is talking about.
>
> So these removed or replaced is done automatically or as I understood
> we do merge and and see conflict and do changes as per necessary?

Ahhh.

Here is one lesson for you to learn first: "Do not top post".  Your
top-posting made me miss the new questions on these two lines.  In the
above quote, I rearranged them to be the bottom.

By default, we do not attempt the content level merges, as that can let
you screw up your merge and allow you to lose your work in progress, when
you check out another branch.  We do however run tree level merges, so
you will carry your local uncommitted changes in the working tree with you
when you check out a different branch.

When you are just starting, make it a habit to commit the work-in-progress
changes you made for the current branch, even if they are not complete,
before checking out another branch. You do not have to worry about what
would happen to the uncommitted changes that way. When you check out the
branch you left again, you "reset HEAD^" to drop the WIP commit and come
back to the state you had.  E.g.

	$ git checkout -b xyzzy master
        $ edit xyzzy.py ;# new file
        $ git add xyzzy.py
        $ git commit -m 'start working on xyzzy feature'
        $ edit xyzzy.py ;# work more
        ... you got bored and want to work on something else ...
        $ git commit -a -m 'WIP'

        $ git checkout -b frotz master
	... at this point, xyzzy.py is removed from the working tree,
        ... as it did not exist in 'master' hence not in 'frotz'.
	$ edit ... ;# do whatever
        $ git commit -a -m 'done with frotz feature'

        $ git checkout xyzzy ;# back on xyzzy branch
	... working tree matches what is in the WIP commit
	$ git reset HEAD^
        ... working tree remains the same, no more WIP commit
	$ edit xyzzy.py ;# continue from where you left off

Try this while you have "gitk" open and see what is happening by observing
its history display (you would have to refresh it) after "git commit",
"git checkout", and "git reset".
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]