a version-control system that mimics some of the basic features of the popular version-control system git, but it is smaller and simpler, and thus named "gitlet"
- Usage
java gitlet.Main init
- Description
- Creates a new gitlet version-control system in the current directory. This system will automatically start with one commit: a commit that contains no files and has the commit message
initial commit
. It will have a single branch:master
, which initially points to this initial commit, andmaster
will be the current branch.
- Usage
java gitlet.Main add [file name]
- Description
- Adds a copy of the file as it currently exists to the staging area (see the description of the
commit
command below).
- Usage
java gitlet.Main commit [message]
- Description
- Saves a snapshot of certain files in the current commit and staging area so they can be restored at a later time, creating a new commit. The commit is said to be tracking the saved files. By default, each commit’s snapshot of files will be exactly the same as its parent commit’s snapshot of files; it will keep versions of files exactly as they are, and not update them. A commit will only update files it is tracking if they have been staged at the time of commit. In this case, the commit will now include the version of the file that was staged instead of the version it got from its parent. A commit will save and start tracking any files that were staged but weren’t tracked by its parent. Finally, files tracked in the current commit may be untracked in the new commit as a result of the
rm
command (see below for more information about therm
command).The bottom line: By default a commit is the same as its parent. Staged and removed files are the updates to the commit.
Some additional points about commit:
- The staging area is cleared after a commit.
- The commit command never adds, changes, or removes files in the working directory (other than those in the
.gitlet
directory). Therm
command will remove such files, as well as somehow marking them to be untracked bycommit
. - Any changes made to files after staging or removal are ignored by the
commit
command, which only modifies the contents of the.gitlet
directory. For example, if you remove a tracked file using the Unixrm
command (rather thangitlet
’s command of the same name), it has no effect on the next commit, which will still contain the version of the file before it was deleted. - After the commit command, the new commit is added as a new node in the commit tree.
- The commit just made becomes the “current commit”, and the current branch’s head pointer now points to it. The branch’s previous head commit is this now commit’s parent commit.
- Each commit should contain the date time it was made.
- Each commit has a log message associated with it that describes the changes to the files in the commit. This is specified by the user. The entire message should take up only one entry in the array
args
that is passed tomain
. To include multiword messages, you’ll have to surround them in quotes. - Each commit is identified by its SHA-1 id, which must include the file (blob) references of its files, parent reference, log message, and commit time.
- Usage
java gitlet.Main rm [file name]
- Description
- Untrack the file; that is, indicate that it is not to be included in the next commit, even if it is tracked in the current commit (the current commit will eventually become the next commit’s parent).
- Usage
java gitlet.Main log
- Description
- Starting at the current head commit, display information about each commit backwards along the commit tree until the initial commit. This set of commit nodes is called the commit’s history. For every node in this history, the information it should display is the commit id, the time the commit was made, and the commit message.
- Usage
java gitlet.Main global-log
- Description
- Like log, except displays information about all commits ever made. The order of the commits does not matter.
- Usage
java gitlet.Main find [commit message]
- Description
- Prints out the ids of all commits that have the given commit message, one per line. If there are multiple such commits, it prints the ids out on separate lines. The commit message is a single operand in the argument of the main method; to indicate a multiword message, put the operand in quotation marks (just like we did for the commit command above). This command must return every matching commit that has ever been made, even those that are not on the current branch. Order of the ids outputted does not matter.
- Usage
java gitlet.Main status
- Description
- Displays what branches currently exist, and marks the current branch with a
*
. Also displays what files have been staged or marked for untracking.
Checkout is a kind of general command that can do a few different things depending on what its arguments are. There are 3 possible use cases. In each section below, you’ll see 3 bullet points. Each corresponds to the respective usage of checkout.
- Usages
-
java gitlet.Main checkout -- [file name]
java gitlet.Main checkout [commit id] -- [file name]
java gitlet.Main checkout [branch name]
- Descriptions
-
- Takes the version of the file as it exists in the head commit, the front of the current branch, and puts it in the working directory, overwriting the version of the file that’s already there if there is one. The new version of the file is not staged.
- Takes the version of the file as it exists in the commit with the given id, and puts it in the working directory, overwriting the version of the file that’s already there if there is one. The new version of the file is not staged.
- Takes all files in the commit at the head of the given branch, and puts them in the working directory, overwriting the versions of the files that are already there if they exist. Also, at the end of this command, the branch given as an argument to this command (specified by
branch name
above) will now be considered the current branch (HEAD). Any files that are tracked in the current branch but are not present in the branch you are checking out are deleted. The staging area is cleared, unless the branch you are checking out to is the current branch (see Failure cases below).
- Usage
java gitlet.Main branch [branch name]
- Description
- Creates a new branch with the given name
branch name
, and points the branch at the current head node. A branch is nothing more than a name for a reference (a SHA-1 identifier) to a commit node. This command does NOT immediately switch to the newly created branch (just as in realgit
). The default branch that is created when you initialize your repository is calledmaster
.
- Usage
java gitlet.Main rm-branch [branch name]
- Description
- Deletes the branch with the given name. This only means to delete the pointer associated with the branch; it does not mean to delete all commits that were created under the branch, or anything like that.
- Usage
java gitlet.Main reset [commit id]
- Description
- Checks out all the files tracked by the given commit. Removes tracked files that are not being tracked in the given commit. Moves the current branch’s pointer and the head pointer 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 forcheckout
. The staging area is cleared. The command is essentiallycheckout
of an arbitrary commit that also changes the current branch head pointer.
- Usage
java gitlet.Main merge [branch name]
- Description
- Merges files from the given branch into the current branch.