3
  1. I forked other repository to my own account.
  2. I cloned this forked repository to my computer.

  3. Now i have 2 changed files, ready to commit them (I do not know why). To update (git rebase) my cloned forked repository from origin, I need to have working directory clean. But i haven't, because of this. The only thing come to my mind is to make working directory clean by DISCARD those changes, and then i get my purpose. How to do this? Is there a way to fix this issue?

Otherwise, I am not able to rebase my local repository.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • possible duplicate of [Reset all changes after last commit in git](http://stackoverflow.com/questions/4630312/reset-all-changes-after-last-commit-in-git) – jub0bs Jan 09 '15 at 18:07

2 Answers2

2

Discard: git reset --hard followed by git clean -d -x -f, as mentioned in "How do I clear my local working directory in git?".
But make sure you didn't want to get back those current modifications: they wouldn't be easy to restore (for the ones added to the index).

But if you want a safer option: git stash.
That would save any current modification in the stash, leaving your working tree clean.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It doesn't work. When i tap `git reset --hard` and then `git rebase upstream/master` i get `Cannot rebase: You have unstaged changes. Please commit or stash them.` – Bartłomiej Semańczyk Jan 10 '15 at 00:10
  • @BartłomiejSemańczyk can you try `git config core.autocrlf false` first? And then `git reset --hard`. – VonC Jan 10 '15 at 09:09
  • The same report as before – Bartłomiej Semańczyk Jan 10 '15 at 11:53
  • @BartłomiejSemańczyk do you have `.gitattributes` files anywhere, with `core.oel` directives in them? – VonC Jan 10 '15 at 11:55
  • @BartłomiejSemańczyk it would explain why the reset --hard doesn't get rid of eol which could have been the "unstaged changes" you see. – VonC Jan 12 '15 at 13:24
  • the changes appear when i fork the cdnjs/cdnjs repo from Github. This is described [here](https://github.com/cdnjs/cdnjs/issues/3650). I have changed files, although i changed nothing. – Bartłomiej Semańczyk Jan 12 '15 at 13:32
  • @BartłomiejSemańczyk and `git config core.autocrlf` (when executed from within your local clone) does return false? – VonC Jan 12 '15 at 13:41
0

There are also two other ways, such as:

git checkout . and git restore .

(the latter is preferred, according to https://www.golinuxcloud.com/git-discard-changes/)

These commands discard changes in all files in that directory.