Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
764 views
in Technique[技术] by (71.8m points)

git - Committing Files Back to GitHub for Windows

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:Androidgit-reposOurProject

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

C:Androidgit-reposOurProjectHostAndroidsrccomourprojectclientSettingsActivity.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...