Git Flashcards

1
Q

Types of VCS

A
  1. Centralized
  2. Decentralized
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Centralized VCS

A

Single Point Of Failure (Google Docs)
Need to be online when making changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

De-Centralized VCS

A
  1. Clone the project
  2. No need to be online while making changes
  3. There can be conflicts while merging the code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Github, Bitbucket, Gitlab

A

Not VCS
Central servers that allows to store codebase managed via git
https://learngitbranching.js.org/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Commit Id

A

Created from the hash of previous commit ids

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Git Rebase

A

Rebasing essentially takes a set of commits, “copies” them, and plops them down somewhere else.

While this sounds confusing, the advantage of rebasing is that it can be used to make a nice linear sequence of commits. The commit log / history of the repository will be a lot cleaner if only rebasing is allowed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Relative Refs

A

hash: fed2da64c0efc5293610bdd892f82a58e8cbc5d8
Specify enough characters of the hash until it uniquely identifies the commit. So I can type fed2 instead of the long string above.
Moving upwards one commit at a time with ^
Moving upwards a number of times with ~<num></num>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Centralized VCS (CVCS)

A

Storage: Files and historical data reside on a central server.
Examples: Subversion (SVN) and Perforce.
Pros: Simplicity and centralized control.
Cons: Single point of failure, limited offline capabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Distributed VCS (DVCS)

A

Every contributor has a complete repository on their local machine.
Examples: Git and Mercurial.
Pros: Full repository backup, enhanced collaboration.
Cons: Complexity, larger repository size due to full copies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Git Branching

A

Purpose: Diverges development from the main line.
Strategies: Feature, release, and long-running branches.
Best Practices: Regular commits, clear naming, and cleanup.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Git Merge

A

Process to combine changes from different branches.
Types: Fast-forward, three-way, and squash merges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Git Rebase

A

Command to rearrange commit history.
Benefits: Provides a cleaner, linear progression of commits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Detached HEAD

A

The term “detached HEAD” in Git refers to a state where the HEAD (the pointer to the current branch or commit) is directly pointing to a commit instead of a branch reference. In this state, you’re no longer on a branch and any commits made will not be associated with a branch, making them somewhat challenging to access or find later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Causes of Detached HEAD State:

A

Checking out a Commit: If you use git checkout <commit-hash>, it switches to that specific commit rather than a branch. This results in a detached HEAD state.</commit-hash>

Checking out Tags: Similar to commits, checking out tags can lead to a detached HEAD state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Implications and Usage of Detached HEAD:

A

Read-Only Mode: You’re in a state where you can view the commit’s content but not directly modify it.

Temporary Inspection: Useful for reviewing historical commits, checking differences, or testing specific historical states of the project.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Risks and Considerations:

A

Lost Changes: Any new commits made in a detached HEAD state might be challenging to find or access later.

Risk of Changes Lost: If you switch away from this state without saving changes or noting down the commit hash, those changes might be lost.

17
Q

Recovering from Detached HEAD:

A

Create a Branch: If you want to keep changes, create a new branch at the current commit: git checkout -b <new-branch-name>. This action will create a branch at the current state, ensuring changes are not lost.</new-branch-name>

Save Changes: You can save changes by creating a new branch or by creating a patch or stash. Then, you can apply them to a branch later.

18
Q

Git Cherry-Pick

A

Git cherry-pick selects and applies individual commits from one branch into another, useful for specific changes without merging entire branch histories.

19
Q

When to Use Cherry-Pick

A

Selective Changes: Apply specific changes from one branch to another without merging entire histories.
Bug Fixes or Feature Backporting: Useful for applying fixes or features from one branch to another.

20
Q

How to Cherry-Pick

A

Identify Commit Hash: Get the hash of the commit you want to cherry-pick.
Switch to Target Branch: Use git checkout [target-branch] to move to the branch you want to modify.
Apply the Commit: Execute git cherry-pick [commit-hash] and resolve conflicts if any. Push changes using git push origin [target-branch].

21
Q

Best Practices for Cherry-Pick

A

Commit Isolation: Cherry-pick works best with isolated commits.
Testing: Always test changes after cherry-picking to ensure functionality isn’t compromised.
Avoid Overuse: Cherry-pick is useful but shouldn’t replace regular merging or rebasing.

22
Q

git pull

A

git fetch + git merge