This is slightly simplified from the real story, but hopefully close enough. Suppose I initially have one branch: develop. Then I create a new branch: release. At this point, release and develop both point to commit XYZ. I do some work on the release branch, and occasionally merge it into develop. Meanwhile, I do lots of other work on the develop branch. Then one day I wake up and wonder when did my branches first diverge? That is, I want to find the commit hash of commit XYZ. The obvious temptation is to use "git merge-base" but this just finds the point when I last merged release into develop, which is WAY later than commit XYZ.
find point where two branches in git FIRST diverged
102 Views Asked by Mark VY At
1
There are 1 best solutions below
Related Questions in GIT
- problem to push files on a repository git
- diff3 output in git conflict style, including mergeable hunks
- Git Not In Sync with Local Branch
- Setting up the version control of .dotfiles while the .config is connected to a forked repo
- How to fix overriding the main branch in Git?
- I can't add text to "Message" in VS Code when committing to Git
- How can i redirect pull request from main branch to another branch
- Xcode commits (possibly outside of any branch) disappeared, how to get them back?
- Git/TortoiseGit : how to apply ONLY the changes from ONE commit from branch A, to branch B?
- How can I reintroduce username an password on git using fedora?
- GIT SKIP EMPTY DIRECTORIES
- Git smudge run once per checkout or per commit?
- I can't find ~/.profile or ~/.bashrc in C:/Users/<user>/.ssh folder
- Set environment variable during push for GitHub Actions
- Android WebRTC compile
Related Questions in VERSION-CONTROL
- Setting up the version control of .dotfiles while the .config is connected to a forked repo
- How can i redirect pull request from main branch to another branch
- Visual Studio 2022 convert spaces to tabs on checkout and back to spaces on checkin
- Handle workspace/monorepo with different deployments
- P4 change ownership through command line
- gitignore for Unity VR project does not work
- Different SDK for specific build
- Sourcetree GUI : Why main branch is behind another branch? Is it normal?
- Strongly Connected Components Using Kosaraju Algorithm
- How to use git-credential-gopass with git send-email?
- Run Robot in Jenkinsfile does not fetch the correct test.robot file from Github
- Git Hub not showing my Organization's Repositories in Android Studio
- Sourcetree caches old branches that no longer exist on github. I do not want this
- How to retrieve Inference image location for my Sagemaker pytorch custom model for Model registry
- I have an error with my Material UI react-swipeable-views in TypeScript
Related Questions in BRANCH
- Xcode commits (possibly outside of any branch) disappeared, how to get them back?
- How to fix "this branch is 1 commit behind of master branch"
- How can I merge these two branches?
- Is there any way for QA to do the feature testing before each feature merged to sacred branches?
- speed up git clone when remote have so many branches
- Cleaning master branch to version from another branch, but save progress to new temp branch
- In Git how can I cycle through previously checked out branches?
- Feature and origin/Feature are separated in a Y shape
- Git how to pull the update from original repository and keep my own changes
- Pull request from feature branch into test branch shows changes that are already inside test branch
- Git rev-parse --abbrev-ref HEAD vs branch --show-current differences in a new init project
- git forward merging a couple of commits only
- ADF Publish Fail - Invalid references or dependencies found
- Merge dev to stage but only specific commits
- Odoo 17 Branches Configuration
Related Questions in BRANCHING-AND-MERGING
- git: merging a branch that's already been merged by mistake
- Submodules: git status vs git checkout - untracked files
- what happens when we add origin before master while merging?
- working with feature branches leave working tree dirty
- Git branching strategy for maintaining a stable release while continuing product development
- Plastic SCM missing both Merge and Switch Workspace menu options, using with Unity
- To create a branch from a git tag is a good practice?
- How do I avoid hardcoding a URL to a backend environment when updating both frontend and backend in one ticket using GitLabs CI/CD?
- Query return more data than will fit on a worksheet. I need to do VLOOKUP for 1 Column, but Merge (Left outer) and filtering 1 crash query
- Gitlab flow Long lived environment branches in Mono Repo keeps growing commit log on Pull Request in Azure repos
- Bypass policies when pushing but Prevent commits to Main Branch
- Git dividing branch for new mechanic and updating both of them automatically
- Why do I see divergent branches git errors when merging code?
- Git branching model for working on multiple versions simultaneously in 2023
- Every pull request merge increments behind commits to the main
Related Questions in DVCS
- cPanel AutoSSL Issue (DCV)
- How to implement a git local and private server?
- DVC mixed lightning pytorch step batch size
- How can I reauthorize DVC with Google Drive for remote storage?
- find point where two branches in git FIRST diverged
- git rename vs delete duplicate heuristic
- Is it safe to merge a branch created from an old commit in two, separate branches that are a lot more recent?
- Is there another way instead of cloning the whole repo in github
- How does version control systems recieve files from Git?
- How can I view the fossil documentation offline?
- DVC Experiment management workflow
- Version control system with working copy auto sync
- Is there a feature to batch upload folders with files in git, svn, hg?
- Does it make sense to use a distributed VCS (DVCS) to work on research code?
- Using p4 zip and unzip to export files from one perforce server to another
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Since both branches have the same root, I think it should be possible to generate a list of commits back to the root commit for each branch, and then compare those two lists reversed until there is a difference. Then the common ancestor commit is the last one before the first difference.
The following command should then print the commit id of the common ancestor commit:
Edit: The sed argument is two delete (
d) commands, separated with semicolon. The first delete is removing lines 1 to 3 (inclusive). The second delete is removing from the first line that starts with either plus or minus, until the last line ($).