Git Cherry-Picking

You can translate the content of this page by selecting a language in the select box.

Ace the AWS Cloud Practitioner Certification CCP CLF-C02 Exam: Prepare and Ace the AWS Cloud Practitioner Certification CCP CLF-C02

What is Git Cherry-Picking?

Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.


AI Unraveled: Demystifying Frequently Asked Questions on Artificial Intelligence

Cherry picking in git means to choose a commit from one branch and apply it onto another.
This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch. In other words, cherry-picking is when you want to take the contents of a single commit from another branch and copy-paste them to a destination branch as a brand new commit.

Quick Summary of Git Cherry-picking steps

  • Find the commit hash you want to cherry-pick.
  • Go to your destination branch.
  • git cherry-pick -x commit-hash
  • Resolve conflicts if they occur.
  • If there are notes in the original commit, copy them over.

Detailed Git Cherry-picking process

  1. From the origin branch where you want to cherry pick from, run this command to get the commit has needed:
    <code
    git reflog.

    </code

  2. Make sure you are on the branch you want to apply the commit to.
    git checkout
    Execute the following for the typical cherry-pick command is simply:
    git cherry-pick commit-hash
    As developers, we often perform a series of steps to achieve our objectives. Showing you an isolated cherry-pick command is the same as throwing you the manual and asking you to read it.
  3. If you cherry-pick from a public branch, you should consider using
    git cherry-pick -x commit-hash
    This will generate a standardized commit message. This way, you (and your co-workers) can still keep track of the origin of the commit and may avoid merge conflicts in the future.
  4. If you have notes attached to the commit they do not follow the cherry-pick. To bring them over as well, You have to use:
    git notes copy from_commit_hash to_commit_hash

References:

Git Cheat Sheet

You can translate the content of this page by selecting a language in the select box.

Ace the AWS Cloud Practitioner Certification CCP CLF-C02 Exam: Prepare and Ace the AWS Cloud Practitioner Certification CCP CLF-C02

Find Useful Git commands in this Git Cheat Sheet.


AI Unraveled: Demystifying Frequently Asked Questions on Artificial Intelligence

Here is a basic Git cheat sheet:

git init – Initialize a new git repository


Ace the AWS Solutions Architect Associates SAA-C03 Certification Exam : Quizzes, Flashcards, Practice Exams, Cheat Sheets, I passed SAA Testimonials, Tips and Tricks to ace the SAA-C03 exam

git clone [repository] – Clone an existing repository

git status – Check the status of your repository

git add [file] – Add a file to the repository

git commit -m "[message]" – Commit changes with a message

git push – Push changes to a remote repository

git pull – Pull changes from a remote repository

git branch – Show the current branch

If you are looking for an all-in-one solution to help you prepare for the AWS Cloud Practitioner Certification Exam, look no further than this AWS Cloud Practitioner CCP CLFC01 book

git branch [branch-name] – Create a new branch

git checkout [branch-name] – Switch to a different branch

git merge [branch-name] – Merge a branch into the current branch

git log – Show the commit history

git diff – Show changes between commits

git reset --hard [commit] – Reset repository to a specific commit

git stash – Stash changes

git stash apply – Apply stashed changes

Please note that this is a basic cheat sheet and git has many more functionalities and options, it is worth reading the git documentation to learn more.

  • Clone a project:
    git clone git_repo_url project_name
  • Switch to a branch locally:
    git checkout branch_name
  • Modify a file, then save and push it to remote repo in current branch
    git add path_to_file_modifeid/file_name
    git commit -m “Description of modification”
    git push
  • Get a new version of a file after modifying local version
    git checkout path_to_file_modified/file_modified
  • Get latest version of current branch
    git fetch
    git pull
    if you have local changes, you will be prompted to commit or stash them before pulling.
  • Create a new branch based on current branch and switch to it
    git checkout –b branch_name
  • Switch to master branch
    git checkout master
  • Merge branch_name to master
    git merge branch_name
  • Delete local branch
    git branch -d branch_name
  • Undo a merge or pull
    git reset –hard
  • Undo a commit locally and on the remote branch
    git reset –hard commit_id
    git push –force
  • Get remote url of a local branch
    git remote show origin

Source: https://git-scm.com

error: Content is protected !!