11

I often work from OpenSSL's git repo. One of the things I test my changes against is a clean copy by issuing make clean; make dclean.

When I performs git pull, git always fails because of all the developer cruft that's removed with dclean (see below). When it fails, git tells me to "commit your changes or stash your changes...". I'm not interested in committing, saving or stashing them. Rather, I'd like to abandon them.

git abandon is not a command. What is the command to abandon changes?


A related question is How do you discard unstaged changes in git?. But the answer is to stash them (if you read the question, you will see none of the answers actually answers the question). But I'm not interested in stashing or saving them. I just want abandon them so I can git pull and go back to work.


$ git pull
remote: Counting objects: 2069, done.
remote: Compressing objects: 100% (872/872), done.
remote: Total 2069 (delta 1022), reused 589 (delta 589), pack-reused 608
Receiving objects: 100% (2069/2069), 3.13 MiB | 1.59 MiB/s, done.
Resolving deltas: 100% (1272/1272), done.
From https://github.com/openssl/openssl
   c40dba9..e0f9bf1  master     -> origin/master
   8a09500..d8a2353  OpenSSL-fips-2_0-dev -> origin/OpenSSL-fips-2_0-dev
   155ca14..f16093d  OpenSSL_0_9_8-stable -> origin/OpenSSL_0_9_8-stable
   690d040..aaa654d  OpenSSL_1_0_0-stable -> origin/OpenSSL_1_0_0-stable
   76b49a8..cc74177  OpenSSL_1_0_1-stable -> origin/OpenSSL_1_0_1-stable
   c59bd61..4d9dc0c  OpenSSL_1_0_2-stable -> origin/OpenSSL_1_0_2-stable
 * [new tag]         OpenSSL-fips-2_0_9 -> OpenSSL-fips-2_0_9
Updating c40dba9..e0f9bf1
error: Your local changes to the following files would be overwritten by merge:
    crypto/aes/Makefile
    crypto/asn1/Makefile
    crypto/bf/Makefile
    crypto/bio/Makefile
    crypto/buffer/Makefile
    crypto/camellia/Makefile
    crypto/cast/Makefile
    crypto/cmac/Makefile
    crypto/cms/Makefile
    crypto/conf/Makefile
    crypto/des/Makefile
    crypto/dh/Makefile
    crypto/dsa/Makefile
    crypto/dso/Makefile
    crypto/ecdh/Makefile
    crypto/ecdsa/Makefile
    crypto/engine/Makefile
    crypto/err/Makefile
    crypto/evp/Makefile
    crypto/hmac/Makefile
    crypto/idea/Makefile
    crypto/lhash/Makefile
    crypto/md4/Makefile
    crypto/md5/Makefile
    crypto/mdc2/Makefile
    crypto/modes/Makefile
    crypto/ocsp/Makefile
    crypto/pem/Makefile
    crypto/pkcs12/Makefile
    crypto/pkcs7/Makefile
    crypto/pqueue/Makefile
    crypto/rand/Makefile
    crypto/rc2/Makefile
    crypto/rc4/Makefile
    crypto/ripemd/Makefile
    crypto/seed/Makefile
    crypto/sha/Makefile
    crypto/srp/Makefile
    crypto/stack/Makefile
    crypto/ts/Makefile
    crypto/txt_db/Makefile
    crypto/ui/Makefile
    crypto/whrlpool/Makefile
    crypto/x509/Makefile
    engines/Makefile
Please, commit your changes or stash them before you can merge.
Aborting
Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885
  • `git clean -df && git checkout --` http://stackoverflow.com/questions/52704/how-do-you-discard-unstaged-changes-in-git – zedfoxus May 30 '15 at 20:37
  • Thanks zedfoxus. To be clear, I checkout with `git clone` and then go to work. I don't have local copies because there's only one set of sources with OpenSSL. So I work directly from the clone. Hence the reason I want to abandon changes, and not re-check things out. (Related: I think git is the wrong tool for the job here because there's only one set of sources. There's no need for the added complexity). – jww May 30 '15 at 20:42
  • Hi Jeff, if you did `git clone` you got the entire remote repo locally on your system. [Git checkout](http://stackoverflow.com/questions/7298598/what-is-the-difference-between-git-clone-and-checkout) does not re-clone. It switches your local copy between branches. Git is a good tool for managing OpenSSL source. More about that some other time. – zedfoxus May 30 '15 at 21:04
  • If you use VS Code, there is a button for each file to discard changes. – zkilnbqi Jan 18 '22 at 18:45

3 Answers3

16

To sync back with the HEAD, it's

git reset --hard HEAD
9

To discard changes you can also use

git checkout -- . 

Check this answer https://stackoverflow.com/a/52713

Community
  • 1
  • 1
jay
  • 2,067
  • 2
  • 16
  • 31
-2

Although @Willie Wheeler answer is perfect and I have used it in the past , I have been at the receiving end mostly because this command just removes without any chance of second thoughts.

You may try git reset --soft