Saturday, May 14, 2011

Unstaged Changes in Git

Most of us are familiar with the staging area in git, i.e. the state between your working tree and your repository. To stage changes one has to make use of the command:
git add

The opposite of staging is unstaging which occurs when one makes changes to the local working tree but the changes are not reflected by the remote repository. For example, consider a file named foo inside a folder oldFolder. If foo is moved from one folder to another, say from oldFolder to newFolder, followed by git add, git commit and git push, in the local working tree foo would now be present inside newFolder instead of oldFolder, while in the remote repository foo would be present inside both newFolder and oldFolder. Both a git pull and git push would tell you that your working tree is up-to-date. Using git status one can see that there's one unstaged change pending, i.e. the deletion of foo from oldFolder. The simplest and most convenient way to handle this situation is using git-gui. To install git-gui on a Debian based Linux distribution use:

sudo apt-get install git-gui

Once git-gui has been installed, load it by typing git gui inside your working tree. On the top left corner under the heading "Unstaged Changes", all files that need to be unstaged will be listed. Now we simply select each file and click "Stage Changed". Once all files move under the heading "Staged Changes (Will Commit)", we need to click "Commit" after entering a commit message. Finally, clicking on "Push" will push these unstaged changes to the remote repository.
Thank you Rodolfo Carvalho for the tip.

No comments:

Post a Comment