1

I cannot figure these out by myself (these are very easy to do with svn/rabbitvcs in Linux)

  1. How to view local changes against central server (origin?) for one file? (graphically)
  2. How to revert local changes for one file?

Also, when i do a pull, i get this error:

n $ git pull
error: Your local changes to the following files would be overwritten by merge:
    Application/powerbar.cpp
Please, commit your changes or stash them before you can merge.
Aborting

But when i do a git diff for the file it does not display anything.

Edit: Turns out that the file is a local file (powerbar.cpp), why does git want to overwrite my local file?

Edit: When i do "git checkout myfile.cpp" the following is displayed: error: path 'myfile.cpp' is unmerged

When i do "git reset myfile.cpp' then what exactly happens? It does NOT revert my local changes.

bup the broker
  • 171
  • 3
  • 9

2 Answers2

1

First, you should use git status to see changes in your local directory. It will show you what you haven't commited. If you have untracked files - that is also a change from git point of view.

Second, if you want to compare your local commits to remote server use

git diff origin/{your_branch}
ZuoLi
  • 383
  • 2
  • 14
  • I don't do local commits, i have the master branch and i commit to the central repository. But still, how do i revert the local changes to get rid of merge conflicts? I know that when i delete the local files then git pull will not download them again for some reason. – bup the broker Nov 12 '14 at 11:58
  • you can do a " git reset --hard " to revert all your local changes if you are not doing any commits in your local , Be careful with this option though it deletes all the local untracked files from your repo and reversts changes. – Ajay Nov 12 '14 at 12:03
  • @bupthebroker you can also use "git stash save" if you need these files, and after commiting get them with "git stash pop" – ZuoLi Nov 12 '14 at 12:07
  • Can i do a git reset --hard for one file only? What is the difference between git reset and git reset --hard, the help page seems to be in some form of cryptic language: http://git-scm.com/docs/git-reset – bup the broker Nov 12 '14 at 12:17
  • @bupthebroker, here is how to reset one specific file: http://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git – ZuoLi Nov 12 '14 at 12:22
  • I just don't get it - that link seems to be for resetting to some specific revision. How can such an easy task be so difficult. I did a clone of the origin at some point in time, then i changed a few files locally. Now i want to revert my local changes in one file. – bup the broker Nov 12 '14 at 12:28
  • @bupthebroker it does not change anything: just find the last commit `abcde` you want your file to get back to (the commit you've cloned from origin) and use `git checkout abcde file/to/restore` – ZuoLi Nov 12 '14 at 12:30
  • so i should write "git checkout origin myfile" ? – bup the broker Nov 12 '14 at 12:31
  • @bupthebroker, no, you should find the hash of the last commit in the origin repository, and use git checkout hash_of_that_commit file/to/restore – ZuoLi Nov 12 '14 at 12:34
  • What does git checkout origin myfile do then? Or what does git reset origin myfile do? – bup the broker Nov 12 '14 at 12:48
1

Okay, figured out question no 2 out as well, therefore posting it as answer.

The source of my confusion lies in the inconsistent command syntax of git (explained by this great article: http://stevebennett.me/2012/02/24/10-things-i-hate-about-git/).

To reset one file in your working directory to its committed state: git checkout file.txt

To reset every file in your working directory to its committed state: git reset --hard

And a final comment if i may: It seems that git has a long way to go to reach the level on consistency, usability and simplicity of svn.

Community
  • 1
  • 1
bup the broker
  • 171
  • 3
  • 9