John Paul Smithdeal
John Paul Smithdeal

Reputation: 46

Push partial file changes in git

I am trying to figure out how to push partial file changes from my local git repo to a tfs git project.

For some background, I have a project that uses an external wsdl. I have a local dev instance of the wsdl on my machine, and the production application will run on a production version of the wsdl hosted on a different server. I have the project in my local git repository pointed to my local dev wsdl, and the production project in tfs pointed to the remotely hosted wsdl.

My issue is that when I push code changes from my local dev repo to the tfs repo, I don’t want my connections to the dev wsdl being pushed with the changes. My end goal is to be able to make code changes, bug fixes, etc, and push those to the tfs repo without changing any of the production configurations.

I may be going about this incorrectly, but figuring out the best way to tackle this is why I’m here. Are there specific procedures developers usually use to handle this kind of situation?

Upvotes: 0

Views: 614

Answers (3)

陈鹏杰
陈鹏杰

Reputation: 1

You can install the "commit groups" vs code plugin, which allows him to upload the grouped files

Upvotes: 0

Bright Ran-MSFT
Bright Ran-MSFT

Reputation: 13944

Here some suggestions maybe you can have a try:

  1. Try using .gitignore for your repository to ignore the files you do not want to push.
  2. If the files you want to push is not too many, generally only several files, you can use the git add command to add these files as the pushed files.

For example:

git add path/to/file1 path/to/file2 path/to/file3
git commit -m "commit message"
git push

In this example, only the files path/to/file1, path/to/file2 and path/to/file3 will be pushed to remote repository.

  1. If there are many changed files you need to push, you can try as the following steps.
  • Make sure the local repository has been up to date with the remote repository. If not, use git pull or git fetch command to update local repository.
  • Copy the local repository to a temporary folder in another directory that outside of the repository directory.
  • Do changes of the code in the temporary folder.
  • Use some the tools, such as Beyond Compare, to extract the changed files you want to push.
  • Copy the extracted files to the local repository to overwrite the original files.
  • Commit and push the changed files.

Upvotes: 1

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31093

Since you have different configuration file between branches, when you perform merge, you would get conflicts. For this scenario, you could check Merge Strategies.

You can also use Git attributes to tell Git to use different merge strategies for specific files in your project. One very useful option is to tell Git to not try to merge specific files when they have conflicts, but rather to use your side of the merge over someone else’s.

This is helpful if a branch in your project has diverged or is specialized, but you want to be able to merge changes back in from it, and you want to ignore certain files. Say you have a database settings file called database.xml that is different in two branches, and you want to merge in your other branch without messing up the database file. You can set up an attribute like this:

database.xml merge=ours

And then define a dummy ours merge strategy with:

$ git config --global merge.ours.driver true

If you merge in the other branch, instead of having merge conflicts with the database.xml file, you see something like this:

$ git merge topic
Auto-merging database.xml
Merge made by recursive.

In this case, database.xml stays at whatever version you originally had.

.gitattributes - is a root level file of your repository that defines the attributes for a subdirectory or subset of files.

Upvotes: -1

Related Questions