How to download the project in two different states - before and after a Pull Request:

46 Views Asked by At

I'm seeking guidance on how to obtain two different states of a project - one before and one after a Pull Request (PR) - using Git commands. Currently, I'm able to view the changes in the PR on GitHub interface, but I need to download the projects in two states(before and after).

Here's what I aim to accomplish:

Retrieve the project state before the PR: I want to download the project state as it was before the PR submission.

Retrieve the project state after the PR: Similarly, I need download to the project state as it appears after the PR submission.

I've tried switching to the main branch, but I'm uncertain how to identify the exact commit hash of the main branch at the time of the PR submission. Is there a straightforward method to directly download the projects in their respective states before and after the PR?

I appreciate any insights or guidance on how to tackle this issue effectively. Thank you!

For example: I want to download the project in two states(the one is the red state,and the other is the green state). enter image description here

3

There are 3 best solutions below

0
tian chen On BEST ANSWER

To get the original state of the project, in most cases a normal clone of the repository is enough:

# 'MyProject' is the name of the target folder, defaults to the Name of the repository
git clone <project-url> MyProject
# Go into the project folder
cd MyProject
# In case you the original state uses the default branch, you are done.
# In case you the target branch is not your default, execute git checkout (your target branch is 'master')
git checkout <targetBranch>```
0
arch On

To get the original state of the project, in most cases a normal clone of the repository is enough (all lines that begin with a '#' are comments):

# 'MyProject' is the name of the target folder, defaults to the Name of the repository
git clone <project-url> MyProject
# Go into the project folder
cd MyProject
# In case you the original state uses the default branch, you are done.
# In case you the target branch is not your default, execute git checkout (your target branch is 'master')
git checkout <targetBranch>

To get the state of the pull request, begin with the steps above, then do the following steps:

# 'prUser1Repo' is can be anything, its just an alias for the remote
# <project-url-of-forked-repository> is the git url of the repository of the user that issued a pull request
git remote add prUser1Repo <project-url-of-forked-repository>
git fetch prUser1Repo
# <feature_branch> is the part after the ':', e.g. in your case "Task/FrameworkPackageUpdate"
git merge prUser1Repo/<feature_branch>

In case there same files have been edited, the final merge may result in a merge request.

2
eftshift0 On

Clone the project.....use the main branch as your after branch.

Then, identify the commit id of the commit where the PR was merged ... Let's say it is x. Now, Crete a branch in the commit befote x with:

git branch before x~ # use the pigtail

Now you switch between branches as needed

git checkout before
.
.
. # work work work
.
.
git checkout main
.
.
. # work work work
.
.
git checkout before