Git Concepts

Version control system. Links: article on what git commit hash is, github workflow

34 flashcards · Programming Languages · by Xiang J

  1. What if your working tree is in a dirty state, but you want to walk around take a look at other branches?

    $ git stash Saved working directory and index state \ "WIP on master: 049d078 added the index file" HEAD is now at 049d078 added the index file (To restore them type "git stash apply") $ git stash list stash@{0}: WIP on master: 049d078 added the index file stash@{1}: WIP on master: c264051 Revert "added file_size" stash@{2}: WIP on master: 21d80a5 added number to log $ git stash apply # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed…

  2. Why create a branch in a fork&branch approach?

    Because if you already sent one pull request, you'll be able to branch out from master once again and submit another pull request easily! Not only is it proper git workflow, but it also keeps your changes organized and separated from the master branch so that you can easily submit and manage multiple pull requests for every task you complete.

  3. Name 6 steps in the fork&branch workflow.

    1. In github (e.g. https://github.com/transloadit/uppy.git) click 2. Then clone your forked repo git clone https://github.com/lakesare/uppy.git 4. Create a new branch git checkout -b new-feature 5. git push origin new-feature 6. And then go to your folder, and click 'Pull Request' Sources: https://blog.scottlowe.org/2015/01/27/using-fork-branch-git-workflow/, https://gist.github.com/Chaser324/ce0505fbed06b947d962

  4. What to do if you want to create a pull request, but don't have write access to the repository?

    Create a fork repository! If you don't have write access to the repository where you'd like to create a pull request, you must create a fork, or copy, of the repository first.

  5. What does git fetch origin do?

    It fetches ALL BRANCHES from the remote named origin.

  6. What does git fetch --all do?

    It fetches all branches from ALL REMOTES.

  7. When thinking about branches, remember that the base branch is where changes should be applied, the head branch contains what you would like to be applied.

  8. How to fetch the PR?

    git fetch upstream pull/1400/head:pr-1400 git checkout pr-1400 https://blog.scottlowe.org/2015/09/04/checking-out-github-pull-requests-locally/

  9. What does WIP stand for in gitkraken?

    Work In Progress

  10. What does git stash apply do?

    It restores the latest stash from git stash list. $ git stash list stash@{0}: WIP on master: 049d078 added the index file stash@{1}: WIP on master: c264051 Revert "added file_size" stash@{2}: WIP on master: 21d80a5 added number to log To apply a specific stash - use git stash apply stash@{2}. _________________________________________________ $ git stash apply # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # # modified: index.html…

  11. What remote is usually called 'upstream'?

    The repository we originally FORKED from. After we FORK the repository - the forked copy in our account is usually named 'origin', and the original repository we forked from - 'upstream'. git remote add upstream https://github.com/transloadit/uppy.git

  12. What's meant by the clean VS dirty state?

    A working tree is said to be dirty if it: contains modifications which have not been committed to the current branch. Dirty working tree: $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: index.html # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # # modified: lib/simplegit.rb Clean working tree: $ git status # On branch master nothing to commit, working directory clean

  13. What to do if you stumbled upon conflict in git rebase?

    If you hit a conflict: resolve the conflicting files, stage the merged changes: git add , continue the rebase: git rebase --continue.

  14. $ git checkout experiment $ git rebase master What will this do?

    Will rebase experiment on top of master. AND this history will be kept at experiment. The rebase command takes a target branch to replay the current branch's commits onto. After the rebase finishes, your current branch will have the commit history from the target branch.

  15. Suppose you have rebased your experiment branch on top of master: $ git checkout experiment $ git rebase master How to merge experiment into master now?

    $ git checkout master Switched to branch 'master' $ git merge experiment Updating 8f7aa27..96a0ff0 Fast-forward myfile.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) With the experiment branch rebased onto master, we can now issue a fast-forward merge.

  16. What is the difference between merge and rebase?

    git checkout hi git merge master git merge - will generate a new commit in hi, preserving the ancestry of each commit history. git checkout hi git rebase master git rebase - merges master into hi, and puts all of the hi commits ON TOP of master.

  17. Whatʼs a Fast Forward Merge?

    Typical merge: when master and a feature branch diverged, and on merge new commit is created. Fast Forward merge: if master and feature branch have not diverged, instead of creating a new commit, git will just point master to the latest commit of the feature branch.

  18. Name 3 options of git reset OPTION 8888 command.

    git reset --soft: undo commits up to 8888 --mixed (default): undo commits up to 8888 unstage everything --hard: undo commits up to 8888 unstage everything update working tree to 8888 ___________________ The reset command overwrites these three trees in a specific order, stopping when you tell it to: Move the branch HEAD points to (stop here if --soft) Make the Index look like HEAD (stop here unless --hard) Make the Working Directory look like the Index

  19. What's another name for index?

    Staging area.

  20. What is HEAD usually? What is detached HEAD?

    HEAD - when you checkout a branch, it's a reference to the last commit in this branch. detached HEAD - state when you checkout a commit (or remote branch, or a ref) instead of a local branch. HEAD is a reference to the last commit in the currently checked-out branch.There is a small exception to this, which is the detached HEAD. A detached HEAD is the situation you end up in whenever you check out a commit (or tag) instead of a branch. In this case, you have to imagine this as a temporary branc…

  21. What is git head VS index VS working tree?

    head - pointer to branch OR commit that you last checked out, and which will be the parent of a new commit if you make it index - staging area, files ready to be committed after git add . working tree - actual files you are working on HEAD is a pointer to the branch or commit that you last checked out, and which will be the parent of a new commit if you make it. For instance, if you're on the master branch, then HEAD will point to master, and when you commit, that new commit will be a descenden…

  22. Name 2 differences between git revert and git reset.

    git revert creates a new commit, so it's safe to use it after we pushed our code git revert can revert a specific commit without affecting all the subsequent commits The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified. Git revert is a safer alternative to git reset in regards to losing work. Links: https://www.a…

  23. In .gitignore /dir VS /dir/?

    /dir will match a file, directory, link, anything named dir /dir/ will match only a directory named dir

  24. What would git reset --hard 880d do?

    It would reset HEAD, index and working tree up to commit 880d.

  25. How is git commit hash generated?

    commit 880d5bda31691c3eecd7c9a1f971ff44d0761d61 Author: lakesare <lakesare@gmail.com> Date: Wed Nov 8 04:55:05 2017 +0500 half-guessed role logic It's a SHA-1 hash of a commit object (commit author, the date, and the stored data).

  26. What would git revert 880d do?

    It creates a new commit that reverts changes OF commit 880d. You can also git revert the revert commit!git revert undoes a single commit—it does not "revert" back to the previous state of a project by removing all subsequent commits. Links: youtube video

  27. How would you go about merging only one specific commit from dev into master branch?

    Discover a hash of the commit you need with git log, suppose it's c90fff git checkout master git cherry-pick c90fff

  28. When is cherry-pick useful?

    A defect is found in production and a fix needs to be implemented against the production-level code. Once the defect is fixed, you'll want to bring this code change back to the development branch so the defect won't be re-introduced into production with a future update. The first option to consider is whether a simple git merge would work. If a merge is possible, that would be the ideal solution. However, if there are other changes that have been made on the production branch that shouldn't be…

  29. What does cherry-pick do?

    Picks a commit from a branch and applies that commit onto another branch.

  30. What does LFS stand for?

    Large File Storage

  31. What does LFS git extension do?

    Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, and stores files on a remote server like GitHub.com or GitHub Enterprise. Git is a distributed version control system, meaning the entire history of the repository is transferred to the client during the cloning process. For projects containing large files, particularly large files that are modified regularly, this initial clone can take a huge amount of time, a…

  32. What does this badge mean?

    That this file is tracked by LFS. git lfs install git lfs track "*.psd" git add file.psd git commit -m "Add design file" git push origin master

  33. What's the difference between rebase and fast-forward?

    rebase creates copies of the original commit but fast-forward does not fast-forward is a special type of merge where the local branch does not have any new commits; otherwise, there will give you an error. https://stackoverflow.com/questions/28140434/is-there-a-difference-between-git-rebase-and-git-merge-ff-only

  34. How to relate commit messages to issues

    Just include #xxx in your commit message to reference an issue without closing it. With new GitHub issues 2.0 you can use these synonyms to reference an issue and close it (in your commit message): fix #xxx fixes #xxx fixed #xxx close #xxx closes #xxx closed #xxx resolve #xxx resolves #xxx resolved #xxx https://stackoverflow.com/questions/1687262/link-to-the-issue-number-on-github-within-a-commit-message