Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
1. The background
We have two branches, dev for test services and FEAT for current requirements development. Normally, we would work on the feat branch, and then we would merge the feat branch into dev as soon as we got there, and that’s what we do every day.
Here’s the problem. One of the stupid things I often do is when I merge my feat branch into my dev branch and stay on my Dev branch, I often forget to switch back to my feat branch and start developing on my Dev branch, write a bunch of code, and then happily add and commit
git add .
git commit -m "Feat: Complete the XXX function"
Copy the code
When you’re ready to push to the far end, Dev dev dev dev dev dev dev dev dev dev dev dev dev dev Dev Dev Now that you’re done, you still have to make sure that the code doesn’t get deleted and you successfully cut to the feat branch.
2. Solutions
Comb through the current situation:
- A bunch of code is written on the dev branch
- Add and commit on the dev branch
Desired purpose:
- Don’t use this stack of code on the dev branch
- Move the stack of code written on the Dev branch to feat
- Once you have successfully moved to the FEAT branch, add, Commit, and push
Solution steps:
- Dev branches
Retracement commit
Without rollback add., runreset
The command
/ / dev branch
git reset --soft HEAD^
Copy the code
- We can’t cut to the feat branch at this point, we need this stack of code
storage
Get up to cut to the feat branch and executestash
Command:
/ / dev branch
git stash
Copy the code
- With stash, the dev branch workspace no longer has this pile of code, so it can
Cut to the feat branch
, the implementation ofcheckout
Command:
/ / dev branch
git checkout feat
Copy the code
- At this point, I’m on the feat branch
The stored code is released
Go to the feat branch and executestash pop
Command:
/ / feat branch
git stash pop
Copy the code
- Commit = commit = commit = commit = commit = commit = commit = commit = commit
/ / feat branch
git commit -m "Feat: Complete the XXX function"
git push origin feat
Copy the code
Here it is: successfully resolved.
Original article, hope to help you, but also for the community to contribute their own strength! Please give a thumbs up if you like
Akiko: A little dream in the front
Home page: To learn more, click on your home page