-1

A very basic question regarding GIT:

how can i delete all commits that were not yet pushed to the remote repository on a way that my modifications on my files will remain?

kapitan
  • 2,008
  • 3
  • 20
  • 26
  • I don't really understand what you really want to do. Could you be more precise? Maybe an example of what you want to accomplish would help to understand the problem. – beni0888 Nov 19 '17 at 15:42
  • apologies for my English. im very new in using GIT. i have made some commits. this commits where not yet pushed on a remote repository. how can i delete all commit entries? also, another questions, my team mates can only see my edited templates only after i pushed them right? – kapitan Nov 19 '17 at 15:45
  • @phd, nope, i just want to delete all commits but i want all modifications on the templates to remain. – kapitan Nov 19 '17 at 15:46
  • Duplicate: https://stackoverflow.com/questions/1611215/remove-a-git-commit-which-has-not-pushed – Sid Nov 19 '17 at 15:49
  • I'm not sure what you mean by "templates": Git has a work-tree in which you have *files*, but as far as Git is concerned, these are just files. Some other program(s) may treat them as templates (whatever that may mean to those other programs). It's worth remembering that Git also has a thing it calls the *index*, which is kind of an intermediate staging area between "commits" (stored mostly-permanently, except for `git reset` as in the answers below) and work-tree. Using `git reset --soft` leaves both the index *and* the work-tree alone. – torek Nov 19 '17 at 16:42
  • @Sid: that one is about using `git reset --hard`, which will re-set the index and work-tree as well. It seems likely that kapitan wants the work-tree, at least, to be undisturbed. (What he wants for the index is not clear.) – torek Nov 19 '17 at 16:44
  • Possible duplicate of [How to undo the last commits in Git?](https://stackoverflow.com/questions/927358/how-to-undo-the-last-commits-in-git) – Jan Zerebecki Nov 19 '17 at 16:46
  • Possible duplicate of [Reset local repository branch to be just like remote repository HEAD](https://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head) – 1615903 Nov 20 '17 at 04:51

4 Answers4

1
git reset --soft origin/master

The command moves HEAD back to the origin branch but preserves working repository.

phd
  • 82,685
  • 13
  • 120
  • 165
1

Can you try this?

git log --oneline
git reset --soft COMMIT

where COMMIT is the latest commit that was pushed to the remote repository.

Tan Nguyen
  • 3,281
  • 1
  • 18
  • 18
1

If you really want to delete the commits, then you need to remove the objects from the key value store.

This can be done by first resetting the branch to the commit before you added any commits.

git reset --soft <COMMIT-SHA>

The --soft flag will keep your working directory. I'm assuming that the templates you are referring to is located somewhere in your working directory?

Typically the COMMIT-SHA will be pointed to by origin/master, if not the find it by doing

git log --oneline

or an equivalent.

When this is done you need to prune the repository.

Here is an answer which explains how

Basically you need to:

git reflog expire --expire-unreachable=now --all
git gc --prune=now

There is not really any reason to do this because eventually git will do this automatically.

smerlung
  • 1,459
  • 1
  • 13
  • 32
0

Trying to understand, we need more details about your question.

You want:

  1. revert a defined set of commits?
  2. revert to the original state (origin/master)?
  3. squash your commits?

It's not your answer, just a tip: use branches.