Git Concepts
Version control system. Links: article on what git commit hash is, github workflow
34 flashcards · Programming Languages · by lakesare
What does cherry-pick do?
Picks a commit from a branch and applies that commit onto another branch.
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…
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
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).
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
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
What would git reset --hard 880d do?
It would reset HEAD, index and working tree up to commit 880d.
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…
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…
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…
What's another name for index?
Staging area.
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.
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.
$ 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.
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.
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.
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
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…
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…
What does WIP stand for in gitkraken?
Work In Progress
What does git fetch --all do?
It fetches all branches from ALL REMOTES.
What does git fetch origin do?
It fetches ALL BRANCHES from the remote named origin.
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
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.
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
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.
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.
In .gitignore /dir VS /dir/?
/dir will match a file, directory, link, anything named dir /dir/ will match only a directory named dir
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/
What does LFS stand for?
Large File Storage
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 lfs install git lfs track "*.psd" git add file.psd git commit -m "Add design file" git push origin master Git LFS is an open source Git extension for versioning large files.
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
What are git submodule?
Submodule is a usual .git repository, but cloned into another git repository. The purpose of the submodule is that it lets you tie the specific commit to the repo you care about.
What's: tag VS release?
tag - git thing Tags are a Git thing. They are a way to mark a specific point in the Git history, such as a release or a version. They can be used to easily refer to a specific version of your code, and can be used to mark a specific version of your code that you want to share with others.release - Github thing GitHub Releases, on the other hand, is a GitHub feature that allows you to package and share software releases. They are built on top of Git tags and provide a way to attach additional m…