1. **Objects**: Git stores data as objects, which include blobs, trees, commits, and tags. Each object is identified by a SHA-1 hash.
2. **Blobs**: These are binary large objects that store the content of files. Each file's content is stored as a blob.
3. **Trees**: Trees represent directories and contain references to blobs (files) and other trees (subdirectories). They maintain the structure of the repository.
4. **Refs**: Refs are pointers to commits. They include branches and tags, allowing Git to track different versions of the project.
Together, these components enable Git to efficiently manage version control and track changes in a repository.
Git cherry-pick is a command that allows you to apply the changes from a specific commit in one branch to another branch. You would use it when you want to selectively apply certain commits without merging the entire branch, such as when you need a bug fix or feature from another branch without bringing in all other changes.
Tags in Git are used to mark specific points in the repository's history, often to denote release versions. To create a tag, use the command `git tag <tag-name>`. To push tags to the remote repository, use `git push origin <tag-name>` or `git push –tags` to push all tags at once.
A remote repository is a version of your project that is hosted on a server, allowing multiple users to collaborate. You connect to a remote repository using Git commands like `git clone` to copy it to your local machine, or `git remote add <name> <url>` to link your local repository to the remote one.
`git fetch` downloads changes from the remote repository to your local repository but does not merge them into your working directory. `git pull` does both: it fetches the changes and then merges them into your current branch.
You can undo a commit that hasn’t been pushed yet by using the command `git reset HEAD~1`. This will remove the last commit while keeping your changes in the working directory.
To resolve merge conflicts in Git, follow these steps:
1. Identify the files with conflicts by running `git status`.
2. Open the conflicted files in a text editor. Look for conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`).
3. Manually edit the file to resolve the conflicts by choosing which changes to keep or combining them.
4. After resolving, save the file.
5. Stage the resolved files using `git add <filename>`.
6. Complete the merge by committing the changes with `git commit`.
A detached HEAD in Git occurs when the HEAD pointer is not pointing to a branch, but directly to a specific commit. This means you are not on a branch, and any new commits will not be associated with any branch until you create a new branch or switch back to an existing one.
Merge combines two branches by creating a new commit that includes changes from both, preserving the history of both branches. Rebase, on the other hand, moves or combines a sequence of commits to a new base commit, creating a linear history without a merge commit.
.gitignore is a file used in Git to specify which files or directories should be ignored by version control. It prevents certain files, like temporary files or sensitive information, from being tracked and included in commits.
A commit in Git is a snapshot of changes made to the files in a repository. It contains the modified files, a unique identifier (hash), the author's information, a timestamp, and a commit message describing the changes.
– **git add**: Stages changes in your working directory for the next commit.
– **git commit**: Records the staged changes in the repository's history with a message.
– **git push**: Uploads your local commits to a remote repository.
Git is a version control system that helps manage and track changes in code, while GitHub is a web-based platform that hosts Git repositories and provides collaboration features for developers.
Git is a distributed version control system used to track changes in source code during software development. It allows multiple developers to collaborate, manage code versions, and maintain a history of changes efficiently.