Git: save specific files without interference

Can I save a file permanently without changes?

I want to:

If there are two branches (A) and (B), they have the same file. For instance,

In branch (A), the setup file has the following:

this is setup in a branch A 

In branch (B), the “setup” file has the following:

 this is setup in a branch B 

These branches do not have uncommitted files (different commits for the same files in different branches).

The GOAL is to prevent these files from being affected after merging these branches.

The solutions in How to tell Git to always choose my local version and Prevent file merging with the wizard using Git do not work. Because they only work in conflict when they are combined. (Well, yes, there will be a conflict if we combine these two branches, and it works once. But if we combine (A) and (B), then (B) - (A), then the files become the same in both branches)

Does Git have such features?

+3
source share
5 answers

No, there is no easy way in git to do this because of how git treats merges.

Maybe I'm wrong, but it looks like you want the configuration files not to merge. It is right? Because there are better / other ways to work with configuration files.

This page describes some solutions to several situations.

Summary:

  • If you can change your program, let others redefine your configuration files that are not tracked.
  • If you cannot change the program, do not track the configuration file itself, but track the template instead.
+4
source

If you really need them to differ from the main and development branches, I recommend the second option to mention in Ikke answer and version 2 value files (one for the wizard and one for the dev branch), plus a template file.

Having multiple value files means that they will not be a merge problem between branches (each user modifies only the value file related to the current branch).
The template file is intended to help the filter filter to generate when checking a private file, which is the actual configuration file (with the correct syntax, from the template file and the correct values, using the file of the correct value after the current branch )

filter driver

+1
source

create a .gitignore file in the directory where the file is located and just put the file name in it!

then run the commend command

git rm -cached path_to_setup.file

So, it will ignore the file in all operations like merge, pull, push, ...

more info: https://help.github.com/articles/ignoring-files

+1
source

A bit long, but use --no-commit for your initial merge step, and then check the source file to make sure it has not been overwritten, and then commit.

There is currently a pre-merge hook list on the git mailing list, which may also give you some options. git list

You can also try the git source code and add the .gitdonotmerge file (to the same directory) along lines like .gitignore (reuse all existing code ;-) and update to combine the stratgetgy options to fix this moderately common problem. The joys of scratching your own open source itch!

+1
source

One parameter git update-index --assume-unchanged [file] , which will ignore changes to the file during setting and fixing, but will leave it in the repository. This is a dangerous command because you need to remember that you assumed that the file does not change when you want to commit the changes. Also, I'm not quite sure how this will behave when merged.

0
source

Source: https://habr.com/ru/post/1432616/


All Articles