shane0 / shane0.github.io

shane null's github pages
https://shane0.github.io/
MIT License
1 stars 0 forks source link

git #14

Open shane0 opened 1 year ago

shane0 commented 1 year ago
git pull --no-ff
shane0 commented 1 year ago

branch workflow

a common Git workflow for creating and merging a feature branch:

Create a new feature branch:

git checkout -b feature-branch

This creates a new branch called "feature-branch" and switches to it.

Make some changes to the feature branch:

git add .
git commit -m "commit message"

This adds all changes to the staging area and creates a new commit with the specified commit message.

Update the feature branch with changes made to master:

git fetch origin
git rebase origin/master

This fetches any changes made to the "master" branch on the remote repository and rebases the "feature-branch" branch onto the latest version of "master".

Continue making changes to the feature branch as necessary, and repeat step 3 as needed.

Once the feature is complete, merge the feature branch into master:

git checkout master
git merge --no-ff feature-branch

This switches to the "master" branch and merges the "feature-branch" branch into it, creating a new merge commit.

Push the changes to the remote repository:

git push origin master

This pushes the changes made to the "master" branch, including the new merge commit, to the remote repository.

Optionally, delete the feature branch:

git branch -d feature-branch

This deletes the local "feature-branch" branch once it's no longer needed.

This workflow ensures that changes made to the "master" branch are incorporated into the feature branch, and that the feature branch is merged back into "master" in a way that preserves the feature history.

shane0 commented 1 year ago
Term Definition
Git A distributed version control system used for tracking changes in source code
Repository A storage location for a project's files and revision history
Commit A snapshot of the project's files at a specific point in time
Branch A separate line of development, created to isolate changes from other branches
Merge The process of combining changes from one branch into another
Pull The process of fetching and merging changes from a remote repository into a local one
Push The process of uploading changes from a local repository to a remote repository
Remote A repository that is hosted on a server or online service
Fork A copy of a repository that can be modified independently from the original
Pull Request A request to merge changes from a forked repository into the original repository
HEAD A reference to the current commit or branch being worked on
Rebase The process of moving a branch to a new base commit, incorporating changes from the old base into the new base
shane0 commented 1 year ago
Term Definition
Git SHA A unique identifier for a specific commit, calculated using the commit's contents
Hash A fixed-length string of characters that represents the contents of a file or data
SHA-1 A cryptographic hash function used by Git to calculate commit identifiers
Object A Git data structure that contains the contents of a file, directory, or commit
Tree A Git object that represents a directory and its contents
Blob A Git object that represents a file and its contents
shane0 commented 1 year ago
Command Purpose
git init Initializes a new Git repository in the current directory
git clone Copies an existing Git repository to a new location
git add Adds changes to the staging area in preparation for committing them to the repository
git commit Creates a new commit object from the changes in the staging area, with a message describing the changes
git push Pushes the changes in the local repository to a remote repository
git pull Fetches changes from a remote repository and merges them into the local repository
git branch Lists, creates, or deletes branches in the local repository
git checkout Switches between branches or commits in the local repository
git merge Merges changes from one branch into another
git status Displays the current status of the local repository, including any changes that are not yet committed
git log Displays the commit history of the local repository
git remote Manages remote repositories that are connected to the local repository
git stash Temporarily saves changes that are not yet ready to be committed
git reset Unstages changes in the local repository
git revert Reverts one or more commits in the local repository
shane0 commented 1 year ago

revert workflow

Step Command
1. Identify commit git log --oneline
git log --oneline
git log --oneline
Identify the commit you want to revert, and copy its SHA identifier
2. Create revert git revert
Creates a new commit that undoes the changes introduced by the specified commit
3. Review changes git diff HEAD^
Review the changes made by the revert commit
4. Commit changes git commit -m "Revert changes from "
Commit the changes made by the revert commit
5. Push changes git push
Push the changes to the remote repository
shane0 commented 1 year ago

cherry pick

Step Command
1. Identify commit git log --oneline
git log --oneline
git log --oneline
Identify the commit you want to cherry-pick, and copy its SHA identifier
2. Create branch git checkout -b
Create a new branch to apply the cherry-picked commit
3. Cherry-pick commit git cherry-pick
Applies the changes introduced by the specified commit to the current branch
4. Resolve conflicts git status
Resolve any conflicts that arise from the cherry-pick, using git add to stage changes
5. Commit changes git commit -m "Cherry-pick changes from "
Commit the changes made by the cherry-pick to the current branch
6. Push changes git push -u origin
Push the changes to the remote repository, and set the upstream branch to track the new branch
shane0 commented 1 year ago

.git folder

File/Directory Description
branches/ Contains files that record the SHA-1 values of the tips of branches in the repository
config Contains configuration settings for the repository, such as the location of remote repositories
description Contains a description of the repository that is displayed in GitWeb, if it is enabled
HEAD Points to the current branch or commit that you have checked out
hooks/ Contains scripts that are run when certain Git events occur, such as committing changes or receiving data over SSH
index Contains a list of files that Git is currently tracking, along with their SHA-1 values and file modes
info/ Contains miscellaneous files that provide information about the repository, such as exclude patterns
logs/ Contains files that record changes to the repository, such as commit messages and ref updates
objects/ Contains Git objects, such as blobs, trees, and commits
refs/ Contains pointers to commits, such as branch and tag names
COMMIT_EDITMSG Contains the commit message entered by the user when creating a new commit
FETCH_HEAD Points to the tip of the branch that was fetched in the most recent Git fetch operation
ORIG_HEAD Points to the commit that was checked out before a merge or rebase operation was performed
MERGE_HEAD Points to the commit that is being merged during a merge operation
CHERRY_PICK_HEAD Points to the commit that is being cherry-picked during a cherry-pick operation
REBASE_HEAD Points to the commit that is being rebased during a rebase operation
REBASE-merge/ Contains files that are used during a rebase operation
refs/original/ Contains a backup of the refs that were updated during a Git filter-branch operation
shane0 commented 1 year ago
Command Description
git init Initializes a new Git repository in the current directory
git clone [repository] Creates a copy of a remote repository in a new directory
git add [file] Adds a file to the staging area
git commit -m [message] Commits changes to the repository with a commit message
git status Displays the status of the working directory
git log Displays the commit history of the repository
git branch [name] Creates a new branch with the specified name
git checkout [branch/commit] Switches to the specified branch or commit
git merge [branch] Merges changes from the specified branch into the current branch
git push [remote] [branch] Pushes changes to the specified branch of a remote repository
git pull [remote] [branch] Fetches changes from a remote repository and merges them into the current branch
git fetch [remote] Fetches changes from a remote repository without merging them
git remote add [name] [url] Adds a new remote repository to the Git configuration
git remote -v Displays a list of remote repositories and their URLs
git diff [file] Shows the differences between the working directory and the staging area or a specified commit
git stash Saves changes to a temporary storage area
git cherry-pick [commit] Applies the changes introduced by the specified commit to the current branch
git revert [commit] Reverts the changes introduced by the specified commit
git reset [commit] Discards changes in the working directory and staging area up to the specified commit