-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vault backup: 2023-12-31 00:58:26 by Zeyad's MacOS
- Loading branch information
1 parent
aaec32a
commit ec518dc
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: Copy Changed Files between git branches | ||
--- | ||
## Intro | ||
In some cases, [`cherry-pick`](https://git-scm.com/docs/git-cherry-pick) commits will be tough when you're working on a git project with a long history and a group of contributors. Conflicts may eat your time and focus leading you to a uncertainty action, or i mean action with no validation either it's wrong or right. | ||
|
||
## Some situations could be solved with different solutions | ||
The solution that will be introduced in this post is tailored specifically to some certain situations, just keep it in your mind, you may find it helpful to you someday. | ||
|
||
1. Generate a file of the changed files by your fingers using your email | ||
|
||
```bash | ||
git log --author "YOUR_EMAIL" --oneline --pretty=format:%H | sort -u | xargs -I {} git show --pretty=format: --name-only {} > changed_files.txt | ||
``` | ||
|
||
The file will be something like this | ||
|
||
```txt | ||
path/file.txt | ||
path/folder/file.ts | ||
``` | ||
|
||
2. Create a new clone of the project with the destination branch. | ||
3. Copy the files from the generated changed file to the destination repo, I use [`rsync`](https://man7.org/linux/man-pages/man1/rsync.1.html) instead of [`cp`](https://man7.org/linux/man-pages/man1/cp.1.html) to copy using the full path. | ||
|
||
```bash | ||
rsync -a --files-from=changed_files.txt . ../cloned-repo-destination-branch | ||
``` | ||
|
||
|
||
> [!warning] The commands run on macOS, find the suitable command lines that do the same thing on your OS. | ||
|
||
## Let's explain the terminal commands | ||
|
||
- Log the commits hashes by specific author using its email | ||
```bash | ||
git log --author "YOUR_EMAIL" --oneline --pretty=format:%H | ||
``` | ||
|
||
- Sort and Just pick the unique, we just need the changed files without repetition. | ||
```bash | ||
sort -u | ||
``` | ||
|
||
- To show just the commit changed files we use this line | ||
```bash | ||
git show --pretty=format: --name-only "hash" | ||
``` | ||
|
||
- Until then we have a list of commits hashes, we need to view the changed files in each commit. we will use [`xargs`](https://man7.org/linux/man-pages/man1/xargs.1.html) here to get the input from the prev commands using pipes | ||
```bash | ||
xargs -I {} | ||
``` | ||
|
||
|
||
Some resources | ||
|
||
- https://mpov.timmorgan.org/use-rsync-instead-of-cp/ | ||
|
||
[[git]] |