Create git commit C that is the inverse of the difference of B and AHow to remove local (untracked) files from the current Git working tree?How to modify existing, unpushed commit messages?What is the difference between 'git pull' and 'git fetch'?How to undo 'git add' before commit?How do I undo the most recent local commits in Git?Find and restore a deleted file in a Git repositoryHow do I delete a Git branch locally and remotely?How to revert a Git repository to a previous commitHow can I reconcile detached HEAD with master/origin?How do I rename a local Git branch?

What calendar would the Saturn nation use?

What's the role of the Receiver/Transmitter in Avengers Endgame?

Concatenate all values of the same XML element using XPath/XQuery

Why always 4...dxc6 and not 4...bxc6 in the Ruy Lopez Exchange?

LiOH hydrolysis of methyl 2,2-dimethoxyacetate not giving product?

Drug Testing and Prescribed Medications

Employee is self-centered and affects the team negatively

How to make a kid's bike easier to pedal

What does the copyright in a dissertation protect exactly?

How could a humanoid creature completely form within the span of 24 hours?

Where do 5 or more U.S. counties meet in a single point?

GitLab account hacked and repo wiped

Extracting the parent, leaf, and extension from a valid path

Does every non-empty set admit an (affine) scheme structure (in ZFC)?

Would a legitimized Baratheon have the best claim for the Iron Throne?

An adjective or a noun to describe a very small apartment / house etc

My parents are Afghan

How to increase row height of a table and vertically "align middle"?

Why did Gendry call himself Gendry Rivers?

Appropriate age to involve kids in life changing decisions

Antivirus for Ubuntu 18.04

How can I finally understand the confusing modal verb "мочь"?

Good introductory book to type theory?

If an attacker targets a creature with the Sanctuary spell cast on them, but fails the Wisdom save, can they choose not to attack anyone else?



Create git commit C that is the inverse of the difference of B and A


How to remove local (untracked) files from the current Git working tree?How to modify existing, unpushed commit messages?What is the difference between 'git pull' and 'git fetch'?How to undo 'git add' before commit?How do I undo the most recent local commits in Git?Find and restore a deleted file in a Git repositoryHow do I delete a Git branch locally and remotely?How to revert a Git repository to a previous commitHow can I reconcile detached HEAD with master/origin?How do I rename a local Git branch?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















So, I have a git repository that I worked on for years in private. Basically, I only used one branch (MASTER), and git was basically like a journal for me. Now, I want to make this source code public, but I want to remove files that I don't have permission to re-distribute. I'd also like to remove some comments that I don't want to make public.



These private comments and undistributable files are still important to me though.



Let's say my most recent commit is called A. I can make a public branch (PUBLIC), and delete everything that can't be public and make a new commit. We'll call that new commit B. Then I can clone that repository, through a number of options, erase the history, then publish the new repository and branch. Then I can work from now on in this public branch with my future collaborators.



This works for the public side of things, but I don't know how to effectively capture what has been deleted. Sure, I have my old branch in my original repository, but it's not really efficient to sort through that to find small comments and changes that I later forgot where deleted from the new public branch.



Is there a way to make a third branch (PRIVATE) that has a new commit, C, represents the difference between A and B?



For example:



Commit A (MASTER)
| | - File 1 (text file)
| | - File 2 (text file)
| | - File 3 (binary file)
| | - File 4 (text file)
| | - File 5 (text file)
| | - File 6 (text file)
| | - File 7 (text file)
| | - File 8 (text file)
| | - File 9 (text file)
| |
| Commit B (PUBLIC)
| - File 1 (text file)
| - File 2 (text file)
| - File 4 (text file)
| - File 7 (same except for line 2 removed)
| - File 8 (same except for line 4 edited)
| - File 9 (same except for a new line inserted between line 8 and line 9)
| - File 10 (new text file)
| - File 11 (new binary file)
|
Commit C (PRIVATE)
- File 3 (binary file)
- File 5 (text file)
- File 6 (text file)
- File 7 (only shows line 2)
- File 8 (only shows the original line 4)


Basically I am trying to take branch MASTER, fork it into a new branch PUBLIC, and then automatically fork branch MASTER into a new branch PRIVATE, whose latest commit contains nothing in the latest commit of PUBLIC. Basically, I want to automatically split, or divide branch MASTER, just be deleting things.




Update



One thing I have done is, after creating Commit B on the PUBLIC branch, switch to the PRIVATE branch, then run



rm -r *
git diff --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, but for File 7 and File 8, it errors out with No such file or directory.



If I instead run



rm -r *
touch "File 7"
touch "File 8"
git diff --unified=0 --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, and File 7, but for File 8 it places some stuff (a changed line) in a file named File 8.rej instead. This is getting closer to what I'm wanting, but using the touch command here isn't practical since I won't know what files actually changed.




Update 2



I can use the following to automatically touch modified files:



git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE


I can also use:



find . -type f -name '*.rej' -print0 | xargs -0 rename -f 's/.rej$//'


if I want to overwrite the empty (touched files) with the .rej files and get rid of the .rej files. However, I'm not sure if a patch on a file can be partially applied, so maybe there will be some cases where there were some changes to the original file (the touched file may not always stay empty) and others go into the .rej file. So, this step may not be totally safe.



What I think I'm opting for at this point is



rm -r *
git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE
git diff --binary --no-ext-diff B..A|git apply --reject


Skipping the --unified=0 option puts both line deletions and line changes into .rej files (I get a File 7.rej and File 8.rej).



In this case, what I'm getting in the PRIVATE branch is, any files deleted in the PUBLIC branch are restored, any files with deletions or changes, I'm getting basically an individual diff for each file, in it's own file. I'm also opting to just leave the .rej files there, since as mentioned above, I don't know if it's safe to do so.



However, this process does not work right for files that are renamed in the PUBLIC branch. If a file is renamed in the PUBLIC branch, the original file just gets completely restored in the PRIVATE branch (as if it were deleted). If a file is modified and renamed, the entire file also gets completely restored in the PRIVATE branch, so you can't tell if anything has been changed or removed inside that file.










share|improve this question



















  • 1





    I didn't read your whole question but do note that commits doesn't capture differences, they capture snapshots of the files. There is no diff actually stored in a git repository, unless you start looking at pack files where some deltas might be stored, but core git doesn't deal in diffs, it deals in snapshots.

    – Lasse Vågsæther Karlsen
    Mar 23 at 17:54

















1















So, I have a git repository that I worked on for years in private. Basically, I only used one branch (MASTER), and git was basically like a journal for me. Now, I want to make this source code public, but I want to remove files that I don't have permission to re-distribute. I'd also like to remove some comments that I don't want to make public.



These private comments and undistributable files are still important to me though.



Let's say my most recent commit is called A. I can make a public branch (PUBLIC), and delete everything that can't be public and make a new commit. We'll call that new commit B. Then I can clone that repository, through a number of options, erase the history, then publish the new repository and branch. Then I can work from now on in this public branch with my future collaborators.



This works for the public side of things, but I don't know how to effectively capture what has been deleted. Sure, I have my old branch in my original repository, but it's not really efficient to sort through that to find small comments and changes that I later forgot where deleted from the new public branch.



Is there a way to make a third branch (PRIVATE) that has a new commit, C, represents the difference between A and B?



For example:



Commit A (MASTER)
| | - File 1 (text file)
| | - File 2 (text file)
| | - File 3 (binary file)
| | - File 4 (text file)
| | - File 5 (text file)
| | - File 6 (text file)
| | - File 7 (text file)
| | - File 8 (text file)
| | - File 9 (text file)
| |
| Commit B (PUBLIC)
| - File 1 (text file)
| - File 2 (text file)
| - File 4 (text file)
| - File 7 (same except for line 2 removed)
| - File 8 (same except for line 4 edited)
| - File 9 (same except for a new line inserted between line 8 and line 9)
| - File 10 (new text file)
| - File 11 (new binary file)
|
Commit C (PRIVATE)
- File 3 (binary file)
- File 5 (text file)
- File 6 (text file)
- File 7 (only shows line 2)
- File 8 (only shows the original line 4)


Basically I am trying to take branch MASTER, fork it into a new branch PUBLIC, and then automatically fork branch MASTER into a new branch PRIVATE, whose latest commit contains nothing in the latest commit of PUBLIC. Basically, I want to automatically split, or divide branch MASTER, just be deleting things.




Update



One thing I have done is, after creating Commit B on the PUBLIC branch, switch to the PRIVATE branch, then run



rm -r *
git diff --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, but for File 7 and File 8, it errors out with No such file or directory.



If I instead run



rm -r *
touch "File 7"
touch "File 8"
git diff --unified=0 --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, and File 7, but for File 8 it places some stuff (a changed line) in a file named File 8.rej instead. This is getting closer to what I'm wanting, but using the touch command here isn't practical since I won't know what files actually changed.




Update 2



I can use the following to automatically touch modified files:



git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE


I can also use:



find . -type f -name '*.rej' -print0 | xargs -0 rename -f 's/.rej$//'


if I want to overwrite the empty (touched files) with the .rej files and get rid of the .rej files. However, I'm not sure if a patch on a file can be partially applied, so maybe there will be some cases where there were some changes to the original file (the touched file may not always stay empty) and others go into the .rej file. So, this step may not be totally safe.



What I think I'm opting for at this point is



rm -r *
git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE
git diff --binary --no-ext-diff B..A|git apply --reject


Skipping the --unified=0 option puts both line deletions and line changes into .rej files (I get a File 7.rej and File 8.rej).



In this case, what I'm getting in the PRIVATE branch is, any files deleted in the PUBLIC branch are restored, any files with deletions or changes, I'm getting basically an individual diff for each file, in it's own file. I'm also opting to just leave the .rej files there, since as mentioned above, I don't know if it's safe to do so.



However, this process does not work right for files that are renamed in the PUBLIC branch. If a file is renamed in the PUBLIC branch, the original file just gets completely restored in the PRIVATE branch (as if it were deleted). If a file is modified and renamed, the entire file also gets completely restored in the PRIVATE branch, so you can't tell if anything has been changed or removed inside that file.










share|improve this question



















  • 1





    I didn't read your whole question but do note that commits doesn't capture differences, they capture snapshots of the files. There is no diff actually stored in a git repository, unless you start looking at pack files where some deltas might be stored, but core git doesn't deal in diffs, it deals in snapshots.

    – Lasse Vågsæther Karlsen
    Mar 23 at 17:54













1












1








1


1






So, I have a git repository that I worked on for years in private. Basically, I only used one branch (MASTER), and git was basically like a journal for me. Now, I want to make this source code public, but I want to remove files that I don't have permission to re-distribute. I'd also like to remove some comments that I don't want to make public.



These private comments and undistributable files are still important to me though.



Let's say my most recent commit is called A. I can make a public branch (PUBLIC), and delete everything that can't be public and make a new commit. We'll call that new commit B. Then I can clone that repository, through a number of options, erase the history, then publish the new repository and branch. Then I can work from now on in this public branch with my future collaborators.



This works for the public side of things, but I don't know how to effectively capture what has been deleted. Sure, I have my old branch in my original repository, but it's not really efficient to sort through that to find small comments and changes that I later forgot where deleted from the new public branch.



Is there a way to make a third branch (PRIVATE) that has a new commit, C, represents the difference between A and B?



For example:



Commit A (MASTER)
| | - File 1 (text file)
| | - File 2 (text file)
| | - File 3 (binary file)
| | - File 4 (text file)
| | - File 5 (text file)
| | - File 6 (text file)
| | - File 7 (text file)
| | - File 8 (text file)
| | - File 9 (text file)
| |
| Commit B (PUBLIC)
| - File 1 (text file)
| - File 2 (text file)
| - File 4 (text file)
| - File 7 (same except for line 2 removed)
| - File 8 (same except for line 4 edited)
| - File 9 (same except for a new line inserted between line 8 and line 9)
| - File 10 (new text file)
| - File 11 (new binary file)
|
Commit C (PRIVATE)
- File 3 (binary file)
- File 5 (text file)
- File 6 (text file)
- File 7 (only shows line 2)
- File 8 (only shows the original line 4)


Basically I am trying to take branch MASTER, fork it into a new branch PUBLIC, and then automatically fork branch MASTER into a new branch PRIVATE, whose latest commit contains nothing in the latest commit of PUBLIC. Basically, I want to automatically split, or divide branch MASTER, just be deleting things.




Update



One thing I have done is, after creating Commit B on the PUBLIC branch, switch to the PRIVATE branch, then run



rm -r *
git diff --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, but for File 7 and File 8, it errors out with No such file or directory.



If I instead run



rm -r *
touch "File 7"
touch "File 8"
git diff --unified=0 --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, and File 7, but for File 8 it places some stuff (a changed line) in a file named File 8.rej instead. This is getting closer to what I'm wanting, but using the touch command here isn't practical since I won't know what files actually changed.




Update 2



I can use the following to automatically touch modified files:



git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE


I can also use:



find . -type f -name '*.rej' -print0 | xargs -0 rename -f 's/.rej$//'


if I want to overwrite the empty (touched files) with the .rej files and get rid of the .rej files. However, I'm not sure if a patch on a file can be partially applied, so maybe there will be some cases where there were some changes to the original file (the touched file may not always stay empty) and others go into the .rej file. So, this step may not be totally safe.



What I think I'm opting for at this point is



rm -r *
git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE
git diff --binary --no-ext-diff B..A|git apply --reject


Skipping the --unified=0 option puts both line deletions and line changes into .rej files (I get a File 7.rej and File 8.rej).



In this case, what I'm getting in the PRIVATE branch is, any files deleted in the PUBLIC branch are restored, any files with deletions or changes, I'm getting basically an individual diff for each file, in it's own file. I'm also opting to just leave the .rej files there, since as mentioned above, I don't know if it's safe to do so.



However, this process does not work right for files that are renamed in the PUBLIC branch. If a file is renamed in the PUBLIC branch, the original file just gets completely restored in the PRIVATE branch (as if it were deleted). If a file is modified and renamed, the entire file also gets completely restored in the PRIVATE branch, so you can't tell if anything has been changed or removed inside that file.










share|improve this question
















So, I have a git repository that I worked on for years in private. Basically, I only used one branch (MASTER), and git was basically like a journal for me. Now, I want to make this source code public, but I want to remove files that I don't have permission to re-distribute. I'd also like to remove some comments that I don't want to make public.



These private comments and undistributable files are still important to me though.



Let's say my most recent commit is called A. I can make a public branch (PUBLIC), and delete everything that can't be public and make a new commit. We'll call that new commit B. Then I can clone that repository, through a number of options, erase the history, then publish the new repository and branch. Then I can work from now on in this public branch with my future collaborators.



This works for the public side of things, but I don't know how to effectively capture what has been deleted. Sure, I have my old branch in my original repository, but it's not really efficient to sort through that to find small comments and changes that I later forgot where deleted from the new public branch.



Is there a way to make a third branch (PRIVATE) that has a new commit, C, represents the difference between A and B?



For example:



Commit A (MASTER)
| | - File 1 (text file)
| | - File 2 (text file)
| | - File 3 (binary file)
| | - File 4 (text file)
| | - File 5 (text file)
| | - File 6 (text file)
| | - File 7 (text file)
| | - File 8 (text file)
| | - File 9 (text file)
| |
| Commit B (PUBLIC)
| - File 1 (text file)
| - File 2 (text file)
| - File 4 (text file)
| - File 7 (same except for line 2 removed)
| - File 8 (same except for line 4 edited)
| - File 9 (same except for a new line inserted between line 8 and line 9)
| - File 10 (new text file)
| - File 11 (new binary file)
|
Commit C (PRIVATE)
- File 3 (binary file)
- File 5 (text file)
- File 6 (text file)
- File 7 (only shows line 2)
- File 8 (only shows the original line 4)


Basically I am trying to take branch MASTER, fork it into a new branch PUBLIC, and then automatically fork branch MASTER into a new branch PRIVATE, whose latest commit contains nothing in the latest commit of PUBLIC. Basically, I want to automatically split, or divide branch MASTER, just be deleting things.




Update



One thing I have done is, after creating Commit B on the PUBLIC branch, switch to the PRIVATE branch, then run



rm -r *
git diff --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, but for File 7 and File 8, it errors out with No such file or directory.



If I instead run



rm -r *
touch "File 7"
touch "File 8"
git diff --unified=0 --binary --no-ext-diff B..A|git apply --reject


This will work for File 3, File 5, File 6, and File 7, but for File 8 it places some stuff (a changed line) in a file named File 8.rej instead. This is getting closer to what I'm wanting, but using the touch command here isn't practical since I won't know what files actually changed.




Update 2



I can use the following to automatically touch modified files:



git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE


I can also use:



find . -type f -name '*.rej' -print0 | xargs -0 rename -f 's/.rej$//'


if I want to overwrite the empty (touched files) with the .rej files and get rid of the .rej files. However, I'm not sure if a patch on a file can be partially applied, so maybe there will be some cases where there were some changes to the original file (the touched file may not always stay empty) and others go into the .rej file. So, this step may not be totally safe.



What I think I'm opting for at this point is



rm -r *
git diff --diff-filter=M -z --name-only B..A| xargs -0 -IREPLACE touch REPLACE
git diff --binary --no-ext-diff B..A|git apply --reject


Skipping the --unified=0 option puts both line deletions and line changes into .rej files (I get a File 7.rej and File 8.rej).



In this case, what I'm getting in the PRIVATE branch is, any files deleted in the PUBLIC branch are restored, any files with deletions or changes, I'm getting basically an individual diff for each file, in it's own file. I'm also opting to just leave the .rej files there, since as mentioned above, I don't know if it's safe to do so.



However, this process does not work right for files that are renamed in the PUBLIC branch. If a file is renamed in the PUBLIC branch, the original file just gets completely restored in the PRIVATE branch (as if it were deleted). If a file is modified and renamed, the entire file also gets completely restored in the PRIVATE branch, so you can't tell if anything has been changed or removed inside that file.







git split branch diff commit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 17:44







user1748155

















asked Mar 23 at 6:19









user1748155user1748155

3961313




3961313







  • 1





    I didn't read your whole question but do note that commits doesn't capture differences, they capture snapshots of the files. There is no diff actually stored in a git repository, unless you start looking at pack files where some deltas might be stored, but core git doesn't deal in diffs, it deals in snapshots.

    – Lasse Vågsæther Karlsen
    Mar 23 at 17:54












  • 1





    I didn't read your whole question but do note that commits doesn't capture differences, they capture snapshots of the files. There is no diff actually stored in a git repository, unless you start looking at pack files where some deltas might be stored, but core git doesn't deal in diffs, it deals in snapshots.

    – Lasse Vågsæther Karlsen
    Mar 23 at 17:54







1




1





I didn't read your whole question but do note that commits doesn't capture differences, they capture snapshots of the files. There is no diff actually stored in a git repository, unless you start looking at pack files where some deltas might be stored, but core git doesn't deal in diffs, it deals in snapshots.

– Lasse Vågsæther Karlsen
Mar 23 at 17:54





I didn't read your whole question but do note that commits doesn't capture differences, they capture snapshots of the files. There is no diff actually stored in a git repository, unless you start looking at pack files where some deltas might be stored, but core git doesn't deal in diffs, it deals in snapshots.

– Lasse Vågsæther Karlsen
Mar 23 at 17:54












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311168%2fcreate-git-commit-c-that-is-the-inverse-of-the-difference-of-b-and-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311168%2fcreate-git-commit-c-that-is-the-inverse-of-the-difference-of-b-and-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript