3

I'm working on an Android project with my colleague and he recently setup a GitHub repo on https://github.com. At my end, I downloaded and installed GitHub for Windows on my 64-bit Windows 7 machine. I then proceeded to go to the repo on GitHub and clone the project using the 'Clone in Windows' button.

Clone in Windows

Everything appeared to go smoothly and the project was at

C:\Android\git-repos\OurProject

on my machine. I then made some changes to the file

C:\Android\git-repos\OurProject\Host\Android\src\com\ourproject\client\SettingsActivity.java

I then observed that the changed file (along with some changed build files) did show up on the version of GitHub I had on my machine like this

http://s11.postimage.org/k8o91hq37/changes_on_github.png

I selected the 'SettingsActivity.java' file, filled in a short description and hit the 'Commit' button. Then I saw the following screen

http://s16.postimage.org/yier6czf9/unsynced_commits.png

Then, when I clicked on 'sync'

sync

hoping the changes I made would be pushed back to the master repo, I got the following message

unstaged changes
You cannot sync with unstaged changes. Please commit your changes and try again.

Why did I get this error message?

I did look at this thread

What's the unstaged changes in github?

and it seems that one has to do the following steps

  1. git add
  2. git commit
  3. git push

but from this thread

What does GitHub for Windows' "sync" do?

it might appear that the 'sync' button does all three? So, I'm not sure how to exactly stage my commits. I thought the fact that I had committed my changes (in the previous step) implied that I had staged them and that is why the option to sync was being offered. Any help in resolving this issue would be much-appreciated.

P.S: I also reached out to the GitHub support team and have posted their solution below as well.

Community
  • 1
  • 1
aLearner
  • 1,051
  • 14
  • 30

2 Answers2

7

Just to add to what VonC wrote...

Each time I attempted to hit the 'sync' button, I was shown the following screen

Unstaged Changes

After reading what he suggested, I clicked on 'Open Shell' and typed

git stash

and it displayed something like this

Power Shell

After this I was able to hit the 'sync' button and it was able to sync successfully.

Added After Reading VonC's Comment

However, after adding that file successfully to the repo, I noticed that the other two build files ('BuildConfig.java' and 'project.properties') were not showing up in GitHub for Windows. So, after reading VonC's suggestion, I typed

git stash pop

in the shell that was opened earlier and then the two files appeared again on GitHub for Windows.

Added After Hearing Back from GitHub Support

Unfortunately you can't sync while you have unstaged changes or files. But there is one workaround:

  1. Commit everything in your working directory (use a commit message of "WIP" or something as short for "Work in Progress")
  2. Sync.
  3. Select the "WIP" commit and click the "rollback to this commit" button.

When you sync, local commits are taken and put at the end of the commits you got from the server.

aLearner
  • 1,051
  • 14
  • 30
  • 1
    Good feedback and illustrations. +1 Don't forget a `git stash pop` to re-apply your work in progress on your (now sync'ed) working tree. And consider setting `core.autocrlf` to false (http://stackoverflow.com/questions/2825428/why-should-i-use-core-autocrlf-true-in-git/2825829#2825829). – VonC Oct 29 '12 at 07:23
  • Thank you. I'll be sure to update the answer above to reflect the use of `stash pop`. I'll also look into `core.autocrlf`. – aLearner Oct 29 '12 at 10:07
  • So I tried to look into `core.autocrlf` but I'm not sure I fully understand how to do this. :-/ – aLearner Oct 29 '12 at 10:38
  • The idea is to make sure git doesn't change anything (in term of newline style) unless you explicitly (as, for instance, in http://stackoverflow.com/a/10855862/6309) configured Git to do so: http://stackoverflow.com/questions/2333424/distributing-git-configuration-with-the-code/2354278#2354278. So : `git config --global auto.corecrlf false` – VonC Oct 29 '12 at 10:39
  • Cool. Thank you for the information and the useful references. This is really helpful. – aLearner Oct 29 '12 at 11:26
  • Except I misspelled the setting: `git config --global core.autocrlf false` (`core.autocrlf`, note `auto.corecrlf` ;) ) – VonC Oct 29 '12 at 11:32
  • Oh thank you for the correction. So, I've been wondering: How does this behavior of changing newline styles on Git exactly occur? Or is it, perhaps, rather random / unpredictable? – aLearner Oct 29 '12 at 16:05
  • Not it is predicable: The idea is to add to the index or the repo (git add / git commit) files with the specified eol style (specified either through local config like `core.autocrlf`, or by metadata files like `core.eol` in a `.gitattributes` files). The problem with the config option is it is a global setting, which means the user isn't always aware of the consequences, and of the impact for *all* the files (as opposed to a `.gitattributes`, when you *declare* explicitly that you want, for certain files only) to change eol. – VonC Oct 29 '12 at 16:09
  • Rollback? as in git revert or git reset? Where are your changes after a rollback? – VonC Oct 30 '12 at 06:18
  • Good questions. Not sure of the answers. GitHub support seems to indicate that "rollback to this commit" is a specific button. I have no idea what it does to the commits, though. :-/ – aLearner Oct 31 '12 at 05:22
  • Could you check your log history right after a Github "rollback to this commit"? – VonC Oct 31 '12 at 06:30
  • Will do after I have an actual commit to make and circle back. Thanks. – aLearner Nov 01 '12 at 05:14
1

You have committed a file, but not all files.
You wouldn't be able to sync with a working tree including some changes in progress.
Said changes need to be stashed, (command-line only, according to "GitHub - Unsynchronized Commit?"), or committed first (as described in this gist).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. So, does this mean that I need to commit _all_ files for it to be able to sync? – aLearner Oct 29 '12 at 06:51
  • @aLearner commit or stash (http://www.kernel.org/pub/software/scm/git/docs/git-stash.html), but since a pull is involved, Git will need a clean working tree in order to realize the sync. – VonC Oct 29 '12 at 06:53
  • Thank you so much! This really did the trick. I'll post a more detailed reply to add to what you wrote above. – aLearner Oct 29 '12 at 07:02