-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.sh
53 lines (45 loc) · 1.01 KB
/
git.sh
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
#!/bin/bash
# Define the directory
dir=$(pwd)
# Check if the directory exists
if [ -d "$dir" ]; then
cd "$dir"
else
echo "Directory $dir does not exist."
exit 1
fi
# Get the current date
riqi=$(date)
# Check if there are any changes
if [ -n "$(git status --porcelain)" ]; then
# Add all changes
git add .
if [ $? -eq 0 ]; then
echo "Changes added successfully."
else
echo "Failed to add changes."
exit 1
fi
# Get the latest changed filename
filename=$(git diff --name-only HEAD | tail -n 1)
# Define a commit message
commit_message="This is for my iPhone git push or pull at $riqi. Last changed file: $filename"
# Commit the changes
git commit -m "$commit_message"
if [ $? -eq 0 ]; then
echo "Changes committed successfully."
else
echo "Failed to commit changes."
exit 1
fi
# Push the changes
git push
if [ $? -eq 0 ]; then
echo "Changes pushed successfully."
else
echo "Failed to push changes."
exit 1
fi
else
echo "No changes to commit."
fi