Lab 2 – Git Commands

I’m new to git and my experiences with it is limited to what I have learned during my Open Source development (DPS909) and data structures and algorithms (BTP500) class. I guess you could call me a git newbie. However, I feel like it is finally time to master git and learn some new commands.

Today I’ve researched and learned two new commands. “git reset” and
“git clean” command. Lets talk about them.g

git reset

What is git reset you ask? well, git reset will reset current HEAD to the specified state. What does that mean you ask? Well, the job of git reset function is to take the current branch and reset it to point somewhere else, and possibly bring the index and work tree along.

git reset [-q] [<tree-ish>] [--] <paths>…​ 
git reset (--patch | -p) [<tree-ish>] [--] [<paths>…​]
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

git reset [<mode>] [<commit>] : This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. If <mode> is omitted, defaults to --mixed. The <mode> must be one of the following:

–soft : Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files “Changes to be committed”, as git status would put it.

–mixed : Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action. If -N is specified, removed paths are marked as intent-to-add (see git-add[1]).

–hard : Resets the index and working tree. Any changes to tracked files in the working tree since <commit>are discarded.

–merge : Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between <commit> and the index has unstaged changes, reset is aborted. In other words, --merge does something like a git read-tree -u -m <commit>, but carries forward unmerged index entries.

–keep : Resets index entries and updates files in the working tree that are different between <commit> and HEAD. If a file that is different between <commit> and HEAD has local changes, reset is aborted.

git clean

what does git clean do? Well it cleans all the files from the working tree. That is as long as they’re not under version control. Now that we know what it is lets look at its options and their explanation.

git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>…​

-d : Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.

-f : If the Git configuration variable clean. requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.

-i : Show what would be done and clean files interactively. See “Interactive mode” for details.

-n : Don’t actually remove anything, just show what would be done.

-q : Be quiet, only report errors, but not the files that are successfully removed.

-e <pattern> : In addition to those found in .gitignore (per directory) and $GIT_DIR/info/exclude, also consider these patterns to be in the set of the ignore rules in effect.

-x : Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.

-X : Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.

Links to Full Documentation

git reset : https://git-scm.com/docs/git-reset

git clean: https://git-scm.com/docs/git-clean

Release 0.1 – Filer Project

This week we were given the opportunity to contribute to our first open source project i.e Filer. The aim of release 0.1 was mostly to help us familiarize ourselves with how git works, how to report a bug, and submit a fix for it.

Changes I made


For the purpose of this project I decided to update the
tests/spec/error.spec.js to use let, const and strict mode instead of var. Reason for doing so was to eliminates some JavaScript silent errors by changing them to throw errors.

Process

  1. Find a project to contribute to.
  2. Submit an issue for the project.
  3. Fork the project.
  4. Clone the fork to my local machine.
  5. Create and checkout a new branch with the issue name.
  6. Open the project using VS Code.
  7. Install the package manager (npm install).
  8. Run the test (npm test).
  9. Fix the bug.
  10. Run the test again to make sure everything still works.
  11. Commit change.
  12. Push change to fork.
  13. Create a pull request on github.
  14. Fix/update the fix according to change request from the moderator/project manager.
  15. push the changes again to be pulled into the master branch.

Conclusion

After finishing this project I feel a greater degree of comfort and confidence in using github and contributing to the interesting projects on it.

Links

Issue: https://github.com/filerjs/filer/issues/664

Pull request created: https://github.com/filerjs/filer/pull/718

Pull request reviewed: 
https://github.com/filerjs/filer/pull/687#issuecomment-198239997