1
//I would like this comment to appear only locally. When I push to a remotely tracked branch, 
//this comment shouldn't appear for other developers to see.

function test(){
  console.log('whatever');
}

test();

I'm not referring to .gitignore as I'm trying to ignore partially parts of the file.

KT-mongo
  • 2,044
  • 4
  • 18
  • 28
  • 2
    How would you envision this working when pulling new changes from a repository? – KoenvE Feb 26 '20 at 12:55
  • Thanks for indicating that. I was sure that question would have been asked but spent a good 10 minutes and couldn't find those answers. – KT-mongo Feb 26 '20 at 14:05
  • @KoenvE: pushing your file with some sort of filter and when pulling, you will be having a conflict for the comments – KT-mongo Feb 26 '20 at 14:08

1 Answers1

1

Git pushes commits, not files. Commits contain files, but each commit contains a full snapshot of all files. Commits also have a unique hash ID that is the same in every Git because it is computed from the complete contents of the commit.

Hence, if you want to have commit X locally in which file F appears "your way", commit X in any Git repository will have that copy of file F. You will have to push to the other Git some different commit Y in which file F appears different. Commits X and Y will be different commits and therefore be different history. From this point forward, your repository and their repository are different repositories unless you let both repositories contain both histories.

It's OK to use the same branch name, in each repository, to refer to different commits and therefore different histories, because branch names are private to each repository; but it is literally impossible to use the same commit, in each repository, to contain different snapshots. The drawback to having their master refer to commit Y (and later, commits derived from Y) while your master refers to commit X (and later, commits derived from X) is that you and/or other people will become confused by this situation.

torek
  • 448,244
  • 59
  • 642
  • 775