Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have two branches namely master and development in a GitHub Repository. I am doing all my development in the development branch as shown.

git branch development

git add *

git commit -m "My initial commit message"

git push -u origin development

Now I want to merge all the changes in the development branch into the master. My current approach is:

git checkout master 

git merge development

git push -u origin master 

Please let me know if the procedure I am following is correct.

1 Answer

0 votes
by (62.9k points)

Find the last commit that affected the given location/path. As the file is not within the HEAD commit, this commit should have deleted it.

git rev-list -n 1 HEAD -- 

Then check out the version at the commit before, using the caret (^) symbol:

git checkout ^ -- 

Or in one command, if $file is the file in question.

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

If you are using zsh and have the EXTENDED_GLOB option enabled, the caret symbol won't work. You can use ~1 instead.

git checkout $(git rev-list -n 1 HEAD -- "$file")~1 -- "$file"

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...