Saving contents of a working directory when going home

Haven't played much with git, so this is more of a "does git supports something like this" question.

You're at work ... working ... you just made a big change, it builds, you made a commit and immediately started working on the next big feature. Made a few changes in the files, but not enough for a commit, and the bell rang. You want to continue working from home, but don't want to dirty the history tree with a partial commit.

Ideally, you could upload the history tree to let's say GitHub and the contents of the working tree, and continue working from home.

Does git supports something like this?

I could always upload the whole thing to an USB and continue from there, but that defeats the whole idea.


提交并推送您的部分更改(最好在故事分支上),然后将中间提交压缩为最终的提交,如下所述:http://gitready.com/advanced/2009/02/10/squashing-commits-with- rebase.html


Simply commit your changes, and then undo that last commit at home (after you pulled) with:

git reset HEAD^

But you will then have to do a forced push ( push -f ) and if anybody else is working on this branch you are going to get into trouble. There are two solutions to this:

  • commit to a different-branch:

    git checkout -b my-temp-branch
    git commit -am "dirty state"
    git push origin my-temp-branch
    

    Then at home, you check out your correct branch, move it to the temp branch, revert the last commit and delete the temp branch:

    git checkout **branch**
    git pull origin my-temp-branch
    git reset HEAD^
    git push --delete origin my-temp-branch
    
  • commit to a different repo. If you do not want to litter your central repo with you temp branches, just create your own repo on github (private if we are talking about company code), set it up as another remote and do the same as in step 1.

    git remote add private **repo**
    

    This needs to be done once, and then when you go home:

    git commit -am "dirty state"
    git push private **branch**
    

    Then at home, you just pull from your private repo and reset the dirty commit

    git checkout **branch**
    git pull private **branch**
    git reset HEAD^
    

  • Git is a distributed revision control and source code.

    So, whenever, we do changes but they are not ready for final commit, so to avoid whole back and start work, Switch to new branch n commit your work.

    git checkout -b <new-branch>
    git add .
    git commit 
    

    Check this one: Move existing, uncommited work to a new branch in Git

    链接地址: http://www.djcxy.com/p/23596.html

    上一篇: Git分支django

    下一篇: 回家时保存工作目录的内容