0

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.

Rook
  • 60,248
  • 49
  • 165
  • 242
  • Ideally you want to always be working on a branch; commit and push the changes to that branch ... then pull them when you get home. – Brian Roach Dec 06 '12 at 07:21
  • 2
    There is generally never a "not enough for a commit" -- at least not in git terms. Your commit policy at work might be different, but that should only ever care about published branches. So yes, as was pointed out, work on an "issue branch", as they are usually called, squash the commit(s) later if needed. Note also "commit --amend" with which you can update the previous commit. – Nevik Rehnel Dec 06 '12 at 07:26

3 Answers3

4

Commit & push your partial changes (preferably on a story branch) then just squash the intermediary commits into a final one like it's described here: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

Eugen Constantin Dinca
  • 8,994
  • 2
  • 34
  • 51
1

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:

  1. 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
    
  2. 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^
    
Chronial
  • 66,706
  • 14
  • 93
  • 99
0

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

Community
  • 1
  • 1
Vinit Prajapati
  • 1,593
  • 1
  • 17
  • 29