SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    739
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question Questoin about GIT (versioning system)

    Hi

    I have a question about GIT.

    Suppose I have a project on MASTER branch with 100s of php files. To do a bug fixing in the project, i create a separate branch

    Code:
    >git checkout -b bugfix
    Then after fixing the bug in 3 files (for eg index.php, register.php and login.php), i merge it in the master branch

    Code:
    >git checkout master
    >git merge bugfix
    The above code will merge all the 3 files i made changes, but is there anyway that i can force GIT to merge only 2 files, say login.php and register.php only?

    Thanks

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,335
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    When you make the commit, you can use the
    Code:
     git add --patch
    to specify only some portions of each file in the commit.
    You also, of course, have the opportunity to specify which files are included in each-and-every commit.

    In your case; "after the fact" I am not sure there is a simply (direct) way to handle this. Of course, you can always
    1. Checkout the bugfix branch
    2. 'touch' the files you want to [ultimately] merge into your master branch
    3. Create a new commit of only those files


    Then you simply merge that latest commit into master.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    739
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thans for the reply.

    But GIT does not allow you to switch to another branch unless u commit all changed files. So in that case how do I merge without switching to another branch?

    Thanks

  4. #4
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,335
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cancer10 View Post
    Hi

    Thans for the reply.

    But GIT does not allow you to switch to another branch unless u commit all changed files. So in that case how do I merge without switching to another branch?

    Thanks
    You can use the `stash` command to 'put aside' all your current work.
    Code:
    git stash
    will bring you to a clean state.
    After you are finished with your changes use
    Code:
    git pop
    to restore your working files.

    You can also simply commit what you have in a new branch. Branches are cheap and easy to use. I often make a branch called "WorkInProgress" to file stuff away while I jump elsewhere to manage some other parts of the project.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,405
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by cancer10 View Post
    The above code will merge all the 3 files i made changes, but is there anyway that i can force GIT to merge only 2 files, say login.php and register.php only?
    You could do it like this:
    Code:
    # On branch master
    git merge --no-commit bugfix
    This will merge the files, but will not commit them, allowing you to remove the one you don't want (index.php in your example) like this:
    Code:
    git reset HEAD index.php
    git checkout -- index.php
    # index.php is now reverted to the master branch version
    and then you can commit the changes as normal.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •