I want to reflect only certain commits locally from the remote repository

Asked 1 years ago, Updated 1 years ago, 42 views

I am a beginner in Visual Studio Community 2019 and version management.
We're starting to build an environment because one activity requires version control.
Please let me know as there is something I don't understand about pull.
Also, if I misunderstand about pull, please let me know.

Can I reflect only certain commitments in the remote repository in the local repository?

For example, suppose a co-developer commits two files in one remote repository, A and B, respectively.Also, I would like to synchronize only the A file of my local repository with the remote repository (I would like to reflect the co-developer commit to the A file of my local repository).What can I do then?

I don't want my local repository's B file to reflect the co-developer's commit.
And I would like to do this on Visual Studio Community.

Currently, we use Azure DevOps for remote repositories, Git for local repositories, and Visual Studio Community 2019.The remote repository is shared with co-developers.

Please let me know if anyone knows.
Thank you for your cooperation.

git

2022-09-30 20:16

2 Answers

A commit in git is a store of the entire state of the repository (under the management folder).

It is possible to extract only individual file changes from specific commitments, but if you don't want to reflect other people's commitments, the benefits of co-editing using Git seem insignificant.

It seems to be a way to cut off the work branch and import the necessary commits (or only certain files) into it.

To remove only the specified file changes from a commit, specify the commit ID and file path in the following format:

$git checkout<commitID><path_to_file>

add
As I mentioned in Answer to similar questions in the past, git pull does fetch+merge behind the scenes, so you shouldn't use git pull if you don't want to include anything.


2022-09-30 20:16

heading

I want to reflect only certain commits locally from the remote repository

and

in the sentence

I want to synchronize only A files with the remote repository

Depending on which you actually want to do in , the former can be done with cherry-pick.

 git fetch

updates the remote-trackng branch, so check the hash value of the commit you want to import from it and

git cherry-pick<Hash value of commit you want to import>

can be captured by the .

In the latter case,

 git fetch

After updating the remote-tracking branch by doing the ,

 git checkout <remote-tracking branch name > --<A file >

It is possible with .
In a recent version (2.23 or later), you can do the same with the command:

git restore --source<remote-tracking branch name>--staged --worktree--<A file>

Also,

I want to leave B in my local area.

If that is the case, I think there is a way of thinking that instead of just taking in the latest state of A file, only B file should be returned to the old state (=the latest state of the local branch before taking in the remote change).


2022-09-30 20:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.