-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-github
More file actions
165 lines (117 loc) · 4.79 KB
/
Copy pathgit-github
File metadata and controls
165 lines (117 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# push a new branch
git checkout -b <branch name>
git add .
git commit -m "<comments>"
git push origin <branch name>
# restore to before any changes made
git restore .
git clean -df
# remote setting
git remote -v
git remote set-url origin <new-url>
# compare two commits in github
https://github.com/<user>/<repo>/compare/58d522a67ef66a616622ef8c0ed71267154df1f9...931e2c14b2858c47245f9c0eacc42950477fa9c0
# git clone a branch
git clone --branch <branch-name> <repository-url>
### bad commit to local and github, revert to the previous step
git log --oneline
git reset --hard <commit has>
git push --force
# new start
git init
git remote add origin <https://github.com/your-username/repo-name.git>
git add .
git commit -m "<comments>"
git branch -M main # rename default branch to main
git push -u origin main
# how to track diff for two unrelated folders (sub-0 is already git initialized and pushed in github)
import os
import shutil
sub0 = "sub-0"
sub1 = "sub-1"
# Get relative paths to all files in sub-0 and sub-1
def get_all_files(root):
files = []
for dirpath, _, filenames in os.walk(root):
for f in filenames:
full_path = os.path.join(dirpath, f)
rel_path = os.path.relpath(full_path, root)
files.append(rel_path)
return set(files)
files_sub0 = get_all_files(sub0)
files_sub1 = get_all_files(sub1)
# Delete files in sub-0 that are not in sub-1
for file in files_sub0 - files_sub1:
path_to_delete = os.path.join(sub0, file)
print(f"Deleting: {path_to_delete}")
os.remove(path_to_delete)
# Add new files from sub-1 to sub-0
for file in files_sub1 - files_sub0:
src = os.path.join(sub1, file)
dst = os.path.join(sub0, file)
os.makedirs(os.path.dirname(dst), exist_ok=True)
print(f"Creating: {dst}")
shutil.copy2(src, dst)
# Overwrite content of matching files
for file in files_sub1 & files_sub0:
path1 = os.path.join(sub1, file)
path0 = os.path.join(sub0, file)
with open(path1, 'r', encoding='utf-8') as f1:
content = f1.read()
with open(path0, 'w', encoding='utf-8') as f0:
print(f"Overwriting: {path0}")
f0.write(content)
git push --set-upstream origin main
on mac #############################################################################################################################################################################################################
Git Workflow for Comparing Two Folder Versions
Scenario
You have an original folder (minutebook_application_original) and an updated folder (minutebook_application), neither initially tracked in Git.
You want to track history with Git and see differences on GitHub.
Step 1: Initialize Git for the Original Folder and Push to GitHub
# Go to the original folder
cd ~/Downloads/excel_generator_streamlit/minutebook_application_original
# Initialize git
git init
# Create a .gitignore to ignore folders like __pycache__, uploads, chroma_db
echo -e "__pycache__/\nuploads/\nchroma_db/" > .gitignore
# Stage all files
git add .
# Commit the original version
git commit -m "Original version"
# Add GitHub remote
git remote add origin https://github.com/username/repo-name.git
# Set main branch
git branch -M main
# Push the original version to GitHub
git push -u origin main
Step 2: Clone the Repo into a Working Folder
cd ~/Downloads/excel_generator_streamlit
# Clone the repo into a new folder
git clone https://github.com/username/repo-name.git minutebook_work
# Enter cloned folder
cd minutebook_work
Step 3: Create a New Branch for the Updated Version
# Create a branch for the new version
git checkout -b updated
Step 4: Copy Updated Files into the Working Folder
# Copy all updated files (including hidden files like .env, .streamlit)
cp -R ../minutebook_application/* .
cp -R ../minutebook_application/.* . # copy hidden files
⚠️ You may get warnings like cp: .: is not a directory. Ignore them for . and .. entries.
Step 5: Stage and Commit Updated Files
git add -A
git commit -m "Updated version from minutebook_application"
Step 6: Push the Updated Branch to GitHub
Option A: If the branch doesn’t exist on remote
git push -u origin updated
Option B: If remote updated branch exists and has different history
# Force push to overwrite remote updated branch
git push -u origin updated --force
windows - power shell###########################################################################################################################################################################################
git clone https://github.com/guochen-code/minuteBook.git minuteBook-github-final_streamlit_application
cd minuteBook-github-final_streamlit_application
git checkout -b azure-deployment
robocopy ../innovation.minuteBook . /E
git add -A
git commit -m "Sync updated project from innovation.minuteBook"
git push -u origin azure-deployment