reset
- Usage:
java gitlet.Main reset [commit id]
- Description: Checks out all the files tracked by the given
commit. Removes tracked files that are not present in that commit.
Also moves the current branch's head to that commit node.
See the intro for an example of what happens to the head pointer
after using reset. The
[commit id]
may be abbreviated as for
checkout
. The staging area is cleared. The command is essentially
checkout
of an arbitrary commit that also changes the current branch
head.
- Runtime: Should be linear with respect to the total size of
files tracked by the given commit's snapshot. Should be constant
with respect to any measure involving number of commits.
- Failure case: If no commit with the given id exists, print
No
commit with that id exists.
If a working file is untracked in the current
branch and would be overwritten by the reset, print
There is an untracked file in the way; delete it, or add and commit it
first.
and exit;
perform this check before doing anything else.
- Dangerous?: Yes!
- Differences from real git: This command is
closest to using the
--hard
option, as in git reset --hard [commit
hash]
.
- Our line count: ~10